时间:2011-07-07 16:13:20

标签: asp.net-mvc

我正在使用ViewPageActivator在视图创建时根据模型的某些属性(如果您熟悉该术语,则为PresentationModel)在视图上设置一些属性。不幸的是,viewpage激活器总是获取控制器上下文,而不是视图上下文(参见下面的代码)。这意味着当视图是模板时,视图页面激活器将获得错误的上下文,如EditorTemplate。激活器不应该总是获得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 个答案:

没有答案