How to import a namespace in Razor View Page?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
I found this http://weblogs.asp.net/mikaelsoderstrom/archive/2010/07/30/add-namespaces-with-razor.aspx which explains how to add a custom namespace to all your razor pages.
Basically you can make this
and put the following code in your AssemblyInfo.cs
the method InitializeApplication will be executed before Application_Start in global.asax
One issue that you must know is that when you import a namespace via
web.config
inViews
folder, thatnamespace
is imported JUST for views in that folder. Means if you want to import anamespace
in an area views, you must also import thatnamespace
, in that area'sweb.config
file, located in area'sViews
folder;Finally found the answer.
For VB.Net:
Take a look at @Javad_Amiry's answer if you want to include a namespace across the app.
In ASP.NET MVC 3 Preview1 you can import a namespace on all your razor views with this code in Global.asax.cs
I hope in RTM this gets done through Web.config section.
"using MyNamespace" works in MVC3 RTM. Hope this helps.
For Library
For Model