Asp.net mvc 具有viewbag数据的linq

Asp.net mvc 具有viewbag数据的linq,asp.net-mvc,linq,dropdown,viewbag,Asp.net Mvc,Linq,Dropdown,Viewbag,控制器 ViewBag.Subdivison = new SelectList(db.Retention_Model_Predictions_DS_Manual.Select(m => m.Underwriter_Name).Distinct(), "Underwriter_Name", "Underwriter_Name"); @Html.DropDownList("Underwriter_Name", null, "Please Select", htmlAttributes: n

控制器

ViewBag.Subdivison = new SelectList(db.Retention_Model_Predictions_DS_Manual.Select(m => m.Underwriter_Name).Distinct(), "Underwriter_Name", "Underwriter_Name"); 
@Html.DropDownList("Underwriter_Name", null, "Please Select", htmlAttributes: new { @class = "form-control" })
查看

ViewBag.Subdivison = new SelectList(db.Retention_Model_Predictions_DS_Manual.Select(m => m.Underwriter_Name).Distinct(), "Underwriter_Name", "Underwriter_Name"); 
@Html.DropDownList("Underwriter_Name", null, "Please Select", htmlAttributes: new { @class = "form-control" })
在控制器中发现错误

ViewBag.Subdivison = new SelectList(db.Retention_Model_Predictions_DS_Manual.Select(m => m.Underwriter_Name).Distinct(), "Underwriter_Name", "Underwriter_Name"); 
@Html.DropDownList("Underwriter_Name", null, "Please Select", htmlAttributes: new { @class = "form-control" })
“错误=无法计算表达式。不支持操作。未知错误:0x80070057。”

视图中发现错误

ViewBag.Subdivison = new SelectList(db.Retention_Model_Predictions_DS_Manual.Select(m => m.Underwriter_Name).Distinct(), "Underwriter_Name", "Underwriter_Name"); 
@Html.DropDownList("Underwriter_Name", null, "Please Select", htmlAttributes: new { @class = "form-control" })
没有类型为“IEnumerable”的ViewData项具有键“Undersier\u Name”

我不这么认为

ViewBag.Subdivison = new SelectList(db.Retention_Model_Predictions_DS_Manual.Select(m => m.Underwriter_Name).Distinct(), "Underwriter_Name", "Underwriter_Name");
是控制器中出现错误的原因

但是,您在视图中收到的错误是因为您的ViewBag名称是
Subdivison
,但您正在调用
unsumer\u name
,作为DropDownList方法中的第一个参数

将视图代码更改为:

@Html.DropDownList("Subdivison", null, "Please Select", htmlAttributes: new { @class = "form-control" })
你拼写错了。。你错过了一个“我”。细分


希望这有帮助。

控制器中的错误是由您上面写的行引起的?