I feel very happy.It encourage me to post more articles.This year I am trying to contribute more.
Once again thanks for your comments and suggestions those helps to me a lot.
Cascading dropdown functionality is common requirement in every web application. Implementing cascading dropdown in JavaScript is very lengthy and takes lot of effort to use AJAX calls .
With jQuery you can write in simple way to achieve this. Here is the code for populate the state dropdown based on the country dropdown selected value.
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$(document).ready(function () {
$("#ddlCountry").change(function () {
var selectedItem = "";
selectedItem = $(this)[0].value; // get the selected ddlCountry id
var url = '/Home/AsyncGetStateList/?countryId=' + selectedItem;
$.get(url, function (data) { // call controller's action
$("#ddrStates").empty();
$.each(data, function (index, optionData) {
$("#ddrStates").append("<option value='"
+ optionData.Text
+ "'>" + optionData.Value
+ "</option>");
});
});
});
});
});
</script>
New optimized code
The above code has totally 21 lines. This we can optimize to 12 lines. Here is the code.
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#ddlCountry").change(function () {
$.getJSON("/Home/AsyncGetStateList", { countryId: $("#ddlCountry option:selected").val() }, function (data) {
$("#ddrStates").empty();
$.each(data, function (index, optionData) {
$("#ddrStates").append("<option value='"
+ optionData.Text
+ "'>" + optionData.Value
+ "</option>");
});
});
});
});
</script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#EFFND').click(function () {
$("#EFFNDP").toggleClass("hidden");
});
});
</script>
This happens due to many reasons.In one my project i have faced this was an image with an
empty “src” property and that would call controller once again.
This is not the issue with ASP.NET MVC .It is browser behavior .If the response form(Web form )
having any broken div tags (Unclosed div tags) or Image source is empty then browser thinking that
form not loaded properly and resubmit the form .It causes to call action method twice in ASP.NET MVC
Precautions to prevent the issue
Once you specify your webpage “url” in the Validator.w3.org site and click on check button .it shows the list of issues and description of respective error
Ex: One of the sample web page I have validated using http://validator.w3.org/ . The result you can find below snap shot
When your run the application with IE browser you will face one issue that is after stop the debugging Visual Studio automatically closes your IE browser
Here is the solution to prevent the closing IE browser
->Click on start debug button in toolbar
->Once the application is running in IE browser
->Click on Detach All as I showing below when ever you don’t want to debug
->Now your browser will not close .
Recently i got this exception when i work with WCF service. One of the Web Method returns heavy data.It is not an issue. The problem hear is maxReceivedMessageSize is exceeded .
The Default value of maxReceivedMessageSize is "65536". We can change this value upto "2147483647".I have increased the size of maxBufferSize,maxReceivedMessageSize in Web.config file (Binding section).
The problem got resolved .
Note: Don’t copy all the code .Only change the maxBufferSize,maxReceivedMessageSize as I specified in below .
<binding name="BasicHttpBinding_Service1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
Happy coding ..
ASP.NET MVC having power full mechanism of model binding.Whatever data HTTP request carries from the client side to server ASP.NET MVC engine
takes the all keys and binds the values to relevant properties .If the Model contains more than one key with same name ASP.NET throws this
exceptions .
Solution :
1.Identify the duplicated properties in the model (May be your model inherited some base model which is having same key )
and rename with unique name
2.Same name with different data types also you will face the exceptions.So change the data type If you have more than
one property in model or base classes.