zoukankan      html  css  js  c++  java
  • MVC 中WebViewPage的运用

    MVC在View的最后处理中是将View的文件页面编译成一个类,这个类必须继承自WebViewPage,WebViewPage默认添加对AjaxHelper和HtmlHelper的支持

    public virtual void InitHelpers()
    {
    Ajax = new AjaxHelper<object>(ViewContext, this);
    Html = new HtmlHelper<object>(ViewContext, this);
    Url = new UrlHelper(ViewContext.RequestContext);
    }
    

    所有当我们在View页面中使用@语法时可以调用Html等方法,观察Orchard及Nop项目对WebViewPage中用的最多的是多语言化

            public Localizer T
            {
                get
                {
                    if (_localizer == null)
                    {
                        //null localizer
                        //_localizer = (format, args) => new LocalizedString((args == null || args.Length == 0) ? format : string.Format(format, args));
    
                        //default localizer
                        _localizer = (format, args) =>
                                         {
                                             var resFormat = _localizationService.GetResource(format);
                                             if (string.IsNullOrEmpty(resFormat))
                                             {
                                                 return new LocalizedString(format);
                                             }
                                             return
                                                 new LocalizedString((args == null || args.Length == 0)
                                                                         ? resFormat
                                                                         : string.Format(resFormat, args));
                                         };
                    }
                    return _localizer;
                }
            }
    

    这俩项目还在自定义的Webviewpage中自定义了一些局部标签。

    在Views中的Web.config中修改如下节点值,可将系统默认webviewpage修改成自定义的

       <system.web.webPages.razor>
            <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <pages pageBaseType="Nop.Web.Framework.ViewEngines.Razor.WebViewPage">
                <namespaces>
                  <add namespace="System.Web.Mvc" />
                  <add namespace="System.Web.Mvc.Ajax" />
                  <add namespace="System.Web.Mvc.Html" />
                  <add namespace="System.Web.Routing" />
                  <add namespace="Nop.Web.Framework" />
                  <add namespace="Nop.Web.Framework.UI" />
                  <add namespace="Nop.Web.Framework.UI.Captcha" />
                </namespaces>
            </pages>
        </system.web.webPages.razor>
    

      

  • 相关阅读:
    HDU1006
    白话经典算法系列之六 高速排序 高速搞定
    pca算法
    硬件这碗饭有那么好吃吗?
    《学会等待》有感
    oracle execute immediate
    HDU 2059 龟兔赛跑
    C++ Tricks(一)—— 判断字符串 string 对象的所有字符都相等
    辨异 —— 数学基本概念
    辨异 —— 数学基本概念
  • 原文地址:https://www.cnblogs.com/xiaoweinet/p/3511070.html
Copyright © 2011-2022 走看看