开发者

MVC ViewPageActivator and the view context

I am using a ViewPageActivator to set some properties on the view based on some properties of the model (PresentationModel if you are familiar with that term) at view creation time. Unfortunately, the viewpage activator always gets the controller context, rather than the view context (see code below). This means that the view page activator will get the wrong context when the vi开发者_StackOverflowew is a template, like an EditorTemplate. Shouldn't the activator always get the viewContext?

    public void Render(ViewContext viewContext, TextWriter writer) {
        if (viewContext == null) {
            throw new ArgumentNullException("viewContext");
        }

        object instance = null;

        Type type = BuildManager.GetCompiledType(ViewPath);
        if (type != null) {
            instance = _viewPageActivator.Create(_controllerContext, type);
        }

        if (instance == null) {
            throw new InvalidOperationException(
                String.Format(
                    CultureInfo.CurrentCulture,
                    MvcResources.CshtmlView_ViewCouldNotBeCreated,
                    ViewPath
                )
            );
        }

        RenderView(viewContext, writer, instance);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜