How do I use an extension method in an ASP.NET MVC View?

后端 未结 2 819
我寻月下人不归
我寻月下人不归 2020-12-03 09:35

How do I access an extension method in an ASP.Net MVC View? In C# I do

using MyProject.Extensions;

and I remember seeing an XML equivalent

相关标签:
2条回答
  • For pages using Razor / WebPages, you can include a using directive in your .cshtml page.

    @using MyBlogEngine;  
    
    0 讨论(0)
  • 2020-12-03 10:28

    In View:

    <%@ Import Namespace="MyProject.Extensions" %>
    

    Or in web.config (for all Views):

    <pages>
      <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="System.Linq" />
        <add namespace="System.Collections.Generic" />
    
        <add namespace="MyProject.Extensions" />
      </namespaces>
    </pages>
    
    0 讨论(0)
提交回复
热议问题