所有工作都可以正常使用,但是在添加一個使用模型'MySite.Models.Cars'返回強類型視圖的新控制器後,在SiteLayout.cshtml中調用Html.Partial(「LogOnPartial」)時出現錯誤。我所說的新的觀點是這樣的:在模板MVC 3項目中調用Html.Partial(「LogOnPartial」)時出錯
return View(db.Cars.FirstOrDefault());
這是錯誤:
The model item passed into the dictionary is of type 'MySite.Models.Cars', but this dictionary requires a model item of type 'MySite.Models.LogOnModel'.
非常沮喪。當我在不提供模型的情況下使用新視圖時,它會再次運行。
return View();
我在MVC 2/ASPX中設置了完全相同的條件,它工作得很好。我不確定這是MVC 2/MVC 3還是ASPX/Razor問題。實際上它可能是一個深夜問題...
非常感謝任何答覆。
編輯:
從LogOnPartial.cshtml第一行(ⅰ除去下劃線)
@model MySite.Models.LogOnModel
第一行從Index.cshtml(新視圖):
@model MySite.Models.Cars
哎喲......我不小心把它強制輸入。它真的很晚。你會得到答案,看起來你可以使用一些額外的點;) – Malako 2011-02-03 06:54:16