我需要你的幫助。通過asp.net中的ViewData.Model發送對象mvc
我試圖通過使用ViewData.Model
這是在控制器
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
dynamic stronglytyped = new { Amount = 10, Size = 20 };
List<dynamic> ListOfAnynomous = new List<object> { new { amount = 10 } };
ViewData.Model = ListOfAnynomous[0];
return View();
}
索引方法對象形成視圖到所述控制器,這是視圖部分
<div>
@Model.amount
</div>
這是erro
'object' does not contain a definition for 'amount'
請任何人都可以幫助我。
請勿使用'object'和'dynamic'。創建視圖模型並將視圖模型傳遞給視圖。 – 2015-04-02 10:00:11
@StephenMuecke謝謝,我得到了解決方案,但請你能解釋爲什麼編譯器沒有看到動態對象定義。 – Moh 2015-04-02 10:29:37
@StephenMuecke我希望把你的評論作爲答案接受 – Moh 2015-04-02 10:39:53