我有一个带有DropDownListFor的.Net核心web应用程序。我有一个AJAX函数,它检查客户在遗留系统上是否有配置文件,然后自动填充值。这非常有效,但在设置dropdownlist的值时,Model值始终为0。
@Html.DropDownListFor(m => m.CountryId, CountryService.List().Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Name }), "select", new { @class = "form-control input-wide input-required" })
Ajax函数
$("#CountryId").val(countryId).change();
$("#CountryId").val(countryId); //tried both
这将设置下拉列表的值,但在单击保存时,CountryId的模型属性始终为0。如果找不到配置文件,并且客户手动注册并选择了国家/地区,它将按预期工作。几乎就像模型没有注意到变化一样?
知道我错过了什么吗?
谢谢。
https://stackoverflow.com/questions/41222190
复制相似问题