我有一个小疑问,即以下方法将对象添加到 ViewData 模型属性。
public ActionResult StronglyTypedView()
{
var obj = new MvcRouting.Models.Student();
obj.age = 24;
obj.name = "prab";
ViewData.Model = obj;
return View();
}
ViewData property
返回类型。ViewDataDictionary
所以我创建了实例ViewDataDictionary
并将对象分配给Model
属性。但是它不起作用,如何解决这个问题?
public ActionResult StronglyTypedView()
{
var obj = new MvcRouting.Models.Student();
obj.age = 24;
obj.name = "prab";
var DicObj = new ViewDataDictionary();
DicObj.Model = obj;
return View();
}