我如何在asp.net mvc中从basecontroller设置基本模型 [英] How do I set the base model from a basecontroller in asp.net mvc

查看:47
本文介绍了我如何在asp.net mvc中从basecontroller设置基本模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个BaseController,我所有站点的控制器都继承自该控制器.

I've got a BaseController that all of my site's controllers inherit from.

我有一个继承自我所有模型的BaseModel.

I've got a BaseModel that all of my Models inherit from.

我想在BaseController的OnActionExecuting方法中设置BaseModel,并将其提供给特定控制器中的特定模型.

I want to set my BaseModel in my BaseController's OnActionExecuting method and make it available to the specific model in the specific controller.

有可能这样吗?

穆斯塔法

推荐答案

像这样吗?

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.Controller.ViewData.Model = new BaseViewModel();;
        }

这篇关于我如何在asp.net mvc中从basecontroller设置基本模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆