Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 由于属性名,所选项目的MVC DropDownList未绑定_C#_Asp.net Mvc_Html.dropdownlistfor - Fatal编程技术网

C# 由于属性名,所选项目的MVC DropDownList未绑定

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

我发现了DropDownListFor不会将viewmodel中的值绑定到列表的一个小例子

下面的代码不会绑定该值

视图模型

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" })