我在这里做错了什么?MVC中的SelectList不正确的语法
我想要做的是将函数值和函数名的列表填充到jSon结果中,然后我将在jQuery的主页上使用它。
的错误是:
错误5无法隐式转换类型 'System.Collections.Generic.IEnumerable' 为 'System.Web.Mvc.SelectList'。一个显式转换存在(是否 缺少强制转换?)
public ActionResult FilterFunctionList(int departmentID = 0)
{
if (departmentID == 0)
{
return this.Json(string.Empty, JsonRequestBehavior.AllowGet);
}
IPACS_Departments ipacs_department = db.IPACS_Department.Find(departmentID);
SelectList ipacs_functions = ipacs_department.IPACS_Functions.Select(m => new SelectListItem
{
Value = SqlFunctions.StringConvert((double)m.functionID).Trim(),
Text = m.name
});
return this.Json(ipacs_functions, JsonRequestBehavior.AllowGet);
}
#endregion
这给了我一个错误说这个功能只能从LINQ调用实体。并指向})倒数第二行。 –
@JamesWilson'IPACS_Functions'的类型是什么? – dasblinkenlight
IPACS_Functions的类型为IPACS_Functions。这是一个自定义实体模型。也许我正在做这个完全错误的事情。 IPACS_Functions模型有很多属性。我所需要的是以json格式返回的每个IPACS_Functions的值/名称。 –