自定义ActionResult返回View = Model是ReadOnly

时间:2011-10-03 01:54:55

标签: asp.net-mvc-3 model actionresult

我在自定义ActionResult中有一段代码

VB.NET版本

Dim result As New ViewResult()
result.Model= data   ## Property Model is ReadOnly
Return result

C#版

ViewResult result = new ViewResult();
result.Model = data;  // Property Model is ReadOnly
return result;

如何从可以包含模型的自定义View中正确返回ActionResult

1 个答案:

答案 0 :(得分:3)

设置

result.ViewData.Model = data; 

应该帮助你。事实上,get ViewResultBase.Model实现为

public object Model 
{
   get {
          return ViewData.Model;
       }
}