我得到的错误信息是:
The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[MvcApplication1.ContentPageNav]', but this dictionary requires a model item of type 'MvcApplication1.ContentPageNav'.
public ActionResult Edit()
{
DataClasses1DataContext dc = new DataClasses1DataContext();
var model = from m in dc.ContentPageNavs
select m;
return View(model);
}
关于我为什么会收到此错误的任何想法?任何帮助将不胜感激。
最佳答案
您正在选择 ContentPageNav
的列表到您的 model
变量中。
该 View 需要一个 ContentPageNav
,而不是它们的列表。
试试这个:
var model = (from m in dc.ContentPageNavs
select m).FirstOrDefault();
关于c# - MVC 给出了一个奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5107579/