在我的应用程序具有以下消息的一个实例: 对象引用不设置为一个对象的一个实例。对象引用不设置为一个对象
@Html.DropDownList("Title",ViewData["PersonTitle"] as SelectList, Model.Person.Title)
下拉列表包含简单的字符串(人物标题)。当您选择一个标题时,该标题应该返回到我的模型。控制器代码:
ViewData["PersonTitle"] = new SelectList(new[] { "Dhr.", "Mevr." });
为什么这不起作用?
编辑:目的是改变
@Html.EditorFor(model => model.Person.Title)
弄成这个样子
@Html.DropDownList("Title",ViewData["PersonTitle"] as SelectList, Model.Person.Title)
可能的复制[什么是一个NullReferenceException,以及如何解决?(http://stackoverflow.com/questions/4660142/what-is-a -nullreferenceexception和知识-DO-I-FIX-IT) – 2017-01-11 10:29:05