Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am getting this error in my code
XML
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'DropDownListFor' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

Source Error:


Line 35:
Line 36:      @Html.LabelFor(model=>model.CountryId)
Line 37:      @Html.DropDownListFor(model=>model.CountryId, Model.AvailableCountries)
Line 38:
Line 39: <br/>



Here's my code


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript" ></script>
<script type="text/javascript">
$(function () {
$("#CountryId").change(function () {
var selectedItem = $(this).val();
var ddlStates = $("#StateId");
var statesProgress = $("#states-loading-progress");
statesProgress.show();
$.ajax({
cache: false,
type: "GET",
url: "@(Url.RouteUrl("GetStatesByCountryId"))",
data: { "CountryId": selectedItem },
success: function (data) {
ddlStates.html('');
$.each(data, function (id, option) {
ddlStates.append($('<option></option>').val(option.id).html(option.name));
});
statesProgress.hide();
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Failed!');
statesProgress.hide();
}
});
});
});
</script>

@Html.LabelFor(model => model.CountryId)
@Html.DropDownListFor(model => model.CountryId, Model.AvailableCountries)




@Html.LabelFor(model => model.StateId)
@Html.DropDownListFor(model => model.StateId, Model.AvailableStates)
Posted
Comments
Nathan Minier 3-Sep-14 13:02pm    
Unless you left it off, I don't see that you've defined a model class.
Abhishek Jaiswall 5-Sep-14 13:09pm    
yaa you are right!

1 solution

solution

add model class as

@model StatesByCountrymodel.Models;
 
Share this answer
 
Comments
Banketeshvar Narayan 14-Mar-15 12:27pm    
Thanks a lot.
I have added it at top line of my view and it resolves my issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900