错误:无法动态分派扩展方法 [英] Error: Extension methods cannot be dynamically dispatched
问题描述
我的代码中出现此错误
Am getting this error in my code
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/>
这是我的代码
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.jstype =text / javascript>< / script>
< script type =text / javascript>
$(function(){
$(#CountryId)。更改(function(){
var selectedItem = $(this).val();
var ddlStates = $(#StateId);
var statesProgress = $(#states-loading-progress);
statesProgress.show();
$ .ajax({
cache:false,
类型:GET,
url:@(Url.RouteUrl(GetStatesByCountryId)),
数据:{CountryId:selectedItem},
成功:函数(数据){
ddlStates.html('');
$ .each(数据,函数(id,选项){
ddlStates.append($('< option>< / option>')。val(选项) .id).html(option.name));
});
statesProgress.hide();
},
错误: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)
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)
推荐答案
(function(){
(function () {
(#CountryId)。change(function(){
var selectedItem =
("#CountryId").change(function () {
var selectedItem =
(这个).val();
var ddlStates =
(this).val();
var ddlStates =
这篇关于错误:无法动态分派扩展方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!