Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?..

like image 582
Shaddix Avatar asked Nov 30 '25 14:11

Shaddix


1 Answers

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

like image 195
Darin Dimitrov Avatar answered Dec 03 '25 12:12

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!