开发者

Custom ActionResult to return View = Model is ReadOnly

开发者 https://www.devze.com 2023-04-09 21:15 出处:网络
I\'ve got a snippet of code in a custom ActionResult VB.NET Version Dim result As New ViewResult() 开发者_C百科result.Model= data## Property Model is ReadOnly

I've got a snippet of code in a custom ActionResult

VB.NET Version

Dim result As New ViewResult()
开发者_C百科result.Model= data   ## Property Model is ReadOnly
Return result

C# Version

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

How do I properly return a View from within a custom ActionResult that can also include the model?


Setting

result.ViewData.Model = data; 

Should help you. In fact, get ViewResultBase.Model is implemented as

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

精彩评论

暂无评论...
验证码 换一张
取 消