初始化配置


1、Asp.Net MVC

  在 Asp.Net MVC 应用程序中,你需要在 Global.cs 中调用绑定验证的方法,如下所示:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        
        //easyui验证绑定
        SettingsBindManager.RegisterBinder("validatebox", new ValidateBoxSettingBinder());
        SettingsBindManager.RegisterBinder("numberbox", new NumberBoxSettingBinder());
    }
}

  然后在所有 Views 目录(包括 Areas)下的 Web.Config 配置文件里添加命名空间 Fireasy.Web.Mvc.Rendering 和 Fireasy.Web.EasyUI,以及 Models 的命名空间,如下所示:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="Fireasy.Web.Mvc" />
        <add namespace="Fireasy.Web.Mvc.Rendering" />
        <add namespace="Fireasy.Web.EasyUI" />
        <add namespace="demo.Models" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

2、Asp.Net Core MVC

  在 Startup.ConfigureServices 方法里的 AddMvc / AddControllersWithViews 之后使用 ConfigureEasyUI 方法:

namespace demo
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddFireasy(Configuration).AddIoc();
#if NETCOREAPP3_1
            services.AddControllersWithViews()
                .ConfigureFireasyMvc()
                .ConfigureEasyUI();;
#else
            services.AddMvc()
                .ConfigureFireasyMvc()
                .ConfigureEasyUI();;
#endif
        }
    }
}

  然后修改所有 Views 目录(包括 Areas)下的 _ViewImports.cshtml 文件,添加命名空间 Fireasy.Web.Mvc.Rendering 和 Fireasy.Web.EasyUI,以及 Models 的命名空间,如下所示:

@using Fireasy.Web.Mvc
@using Fireasy.Web.Mvc.Rendering
@using Fireasy.Web.EasyUI
@using demo.Models

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers