我有一个非常基本的自定义WebViewPage
类,我想在其中为自定义属性分配一个值。这是我的代码:
public abstract class WebViewPage :
System.Web.Mvc.WebViewPage {
public Employee UserPrincipal { get; set; }
public override void Execute() {
// Controller is also a custom class that contains the same property which is injected by
// a custom ActionFilterAttribute. I've confirmed that the attribute is correctly updating
// the property.
Controller controller = (this.ViewContext.Controller as Controller);
if (controller != null) {
this.UserPrincipal = controller.UserPrincipal;
}
}
}
<pages pageBaseType="X.Mvc.WebViewPage">
<!--System.Web.Mvc.WebViewPage-->
据我所知,Execute
由于某种原因未调用该方法,因为我从未遇到过放入该方法的任何断点。我已经正确地更新了Web.config以指向我的自定义,WebViewPage
并且可以从视图中访问该属性,但似乎无法正确设置该属性。
如果有人能指出我正确的方向,我将不胜感激。
好了,我不知道为什么Execute
没有被调用,但InitializePage
是,所以我推翻它,而不是。这有效:
public abstract class WebViewPage :
System.Web.Mvc.WebViewPage {
public Employee UserPrincipal { get; set; }
protected override void InitializePage() {
base.InitializePage();
Controller controller = (this.ViewContext.Controller as Controller);
if (controller != null) {
this.UserPrincipal = controller.UserPrincipal;
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句