Sam*_*amo 3 c# asp.net-mvc actionresult viewmodel
试图避免在这里重复.我在基类控制器中有一个动作,我不允许修改.我希望我的动作做一些检查,调用基类操作,并在渲染之前以某种方式修改结果.但我需要做的部分工作包括修改一些属性,ViewModel
基类返回一个ActionResult
.我看不出有什么办法让ViewModel
从ActionResult
,所以我可能会写一个自定义的方法,其中大部分只会模仿什么的基类是做.我强烈不愿意这样做.有什么建议?
那是因为它ActionResult
是一个相当高级的基类.尝试将其转换为适当的子类型,例如ViewResult
.
快速示例代码:
public ActionResult WrapperAction()
{
// do your initial stuff
// call your base controller action and cast the result
// it would be safer to test for various result types and handle accordingly
ViewResult result = (ViewResult)base.SomeAction();
object model = result.ViewData.Model;
// do something with the model
return result;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4853 次 |
最近记录: |