Using @helpers from another View in Razor ASP.Net MVC3

爷,独闯天下 提交于 2019-12-01 07:44:10

问题


I want to write a few simple @helpers to use in several views. I want them to be inside a Razor .cshtml file (not in a c# class) to have the HTML syntax highlighted.

I can easily access @helpers written within the same View, I can separate them into Helpers.cshtml, and if I put this Helpers.cshtml into an App_Code folder I can access it from any View via @Helpers.MyHelper(). But I want them to be accessible only for a few pages.

I think, it could be like putting a @using if the helpers are in c# class, but what is the namespace for just another view?..


回答1:


Sorry, but that's not possible with helpers stored in the App_Code folder as .cshtml files. They will be shared among all views.



来源:https://stackoverflow.com/questions/6079981/using-helpers-from-another-view-in-razor-asp-net-mvc3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!