c# - Import Razor @helper from Class Project -


is there way import dll class project (or maybe web application project) web application project , reuse @helper? reusability web applications razor seems pretty 0 if cannot achieved.

you can it, have jump through several hoops.

  1. you need obtain razorgenerator: "this custom tool visual studio allows processing razor files @ design time instead of runtime, allowing them built assembly simpler reuse , distribution. "

  2. using razorgenerator, can create .cshtml files in class library project declare helper functions. example, in file called foo.cshtml:

    @helper myhelper(string parameter) {<text>@parameter</text>} 
  3. these helpers exist static methods in static class representing .cshtml file. in above example, translate foo.myhelper.

  4. you can invoke these static methods web application's .cshtml file other static method. (assuming you've added correct using directives point namespace containing helper.) example:

    <div>@foo.myhelper("hello world")</div> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -