我有一个基本控制器类:
和所有我的其他控制器继承这个BaseClass像这样
所有这些工作伟大的MVC3(测试今天,它真的工作),但似乎在BaseController的ExecuteCore不会被触发任何更多的MVC 4 beta。
任何想法?或者什么巨大已经改变了引擎盖下?非常感谢。
public class BaseController : Controller { private string _myData; public string MyData { get { return _myData; } } protected override void ExecuteCore() { _myData = "I am doing something"; base.ExecuteCore(); } } public class HomeController : BaseController { public ActionResult Index() { ViewBag.MyData = MyData; // Doing something with value in BaseClass return View(); } }
解决方法
我能够重现你的问题。看来ExecuteCore的用法被改变了。但我没有找到任何有关它的信息。我的猜测它与事实,现在的Controller实现IAsyncController而不是AsyncController。
将此添加到BaseContoller:
protected override bool disableAsyncSupport { get { return true; } }
从MSDN页面为DisableAsyncSupport(强调由我添加):
This flag is for backwards compatibility. ASP.NET MVC 4. allows a controller to support asynchronous patterns. This means
ExecuteCore
doesn’t get called on derived classes. Derived classes can override this flag and set totrue
if they still needExecuteCore
to be called.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。