如何在 ASP.NET MVC 视图中使用扩展方法? [英] How do I use an extension method in an ASP.NET MVC View?
本文介绍了如何在 ASP.NET MVC 视图中使用扩展方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 ASP.Net MVC 视图中访问扩展方法?在 C# 中我做
How do I access an extension method in an ASP.Net MVC View? In C# I do
using MyProject.Extensions;
我记得看到过一个等效于放入视图的 XML,但我再也找不到了.
and I remember seeing an XML equivalent to put in a view, but I can't find it anymore.
推荐答案
在视图中:
<%@ Import Namespace="MyProject.Extensions" %>
或在 web.config 中(对于所有视图):
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>
这篇关于如何在 ASP.NET MVC 视图中使用扩展方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文