C# 由于属性名,所选项目的MVC DropDownList未绑定
我发现了DropDownListFor不会将viewmodel中的值绑定到列表的一个小例子 下面的代码不会绑定该值 视图模型C# 由于属性名,所选项目的MVC DropDownList未绑定,c#,asp.net-mvc,html.dropdownlistfor,C#,Asp.net Mvc,Html.dropdownlistfor,我发现了DropDownListFor不会将viewmodel中的值绑定到列表的一个小例子 下面的代码不会绑定该值 视图模型 public class PersonViewModel { [Required] public Title? Title { get; set; } public IEnumerable<SelectListItem> TitleSelectList { get; set; } } 看法 更改属性名称可以修复此问题 是否将viewm
public class PersonViewModel
{
[Required]
public Title? Title { get; set; }
public IEnumerable<SelectListItem> TitleSelectList { get; set; }
}
看法
更改属性名称可以修复此问题 是否将viewmodel更改为公共标题?TitleTesting{get;set;}并更新代码的其余部分以匹配它将起作用
我想知道这是错误还是保留字。可能与
ViewBag.Title
public ActionResult Person()
{
return View(
new PersonViewModel
{
Title = Title.Mrs,
TitleSelectList = EnumHelper.GetSelectList(typeof(Title)),
});
}
@Html.DropDownListFor(model => model.Title, Model.TitleSelectList, "Please select...", new { @class = "form-control" })