ExecuteCore()在基类MVC 4 beta中没有被解雇 [英] ExecuteCore() in base class not fired in MVC 4 beta
问题描述
我有一个基础类:
和我的所有其他控制器继承此BaseClass的这样
这所有MVC3的伟大工程(再次测试今天,它确实有效),但它似乎在BaseController的ExecuteCore没有打响了MVC 4 beta中了。
你知道吗?或任何有巨大的引擎盖下的变化?非常感谢。
公共类BaseController:控制器
{
私人字符串_myData; 公共字符串迈德特
{
得到
{
返回_myData;
}
} 保护覆盖无效ExecuteCore()
{
_myData =我正在做的事情; base.ExecuteCore();
}
}
公共类HomeController的:BaseController
{
公众的ActionResult指数()
{
ViewBag.MyData = MyData的;
//用做有价值的东西在的BaseClass 返回查看();
}
}
我能够重现你的问题。看来, ExecuteCore
的使用被改变。但我还没有找到关于它的任何信息。我想这是相关的事实,现在控制器
工具 IAsyncController
不是 AsyncController
。
不过,我已经找到一个解决办法来获取旧的行为与MVC4:
这添加到 BaseContoller
:
保护覆盖布尔DisableAsyncSupport
{
获得{返回true; }
}
从MSDN页面<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.disableasyncsupport%28v=vs.108%29.aspx\"相对=nofollow> DisableAsyncSupport (强调由我添加):
此标志是为了向下兼容。 ASP.NET MVC 4.允许控制器支持异步模式。这意味着
ExecuteCore
不会被调用的派生类。 派生的类可以覆盖此标志,并设置为真正
如果他们仍然需要ExecuteCore
被调用。
块引用>I have a base controller class:
And all my other controller inherits this BaseClass like this
All this works great in MVC3 (test again today, it really works) but it seems that the ExecuteCore in BaseController is not fired any more in MVC 4 beta.
Any idea? Or Anything huge has changed under the hood? Thanks very much.
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(); } }
解决方案I was able to reproduce your problem. It seems that the usage of
ExecuteCore
is changed. But I haven't find any information about it. My guess it's related to the fact that now theController
implementsIAsyncController
not theAsyncController
.However I've found a workaround to get the old behavior with MVC4:
Add this to the
BaseContoller
:protected override bool DisableAsyncSupport { get { return true; } }
From The MSDN page for DisableAsyncSupport (emphasis add by me):
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.
这篇关于ExecuteCore()在基类MVC 4 beta中没有被解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!