Can I have private functions or private declarative helpers within a declarative helper?

141 views Asked by At

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

My environment: ASP.NET MVC3 with Razor.

I have some reusable view logic in declarative helpers in the App_Data directory, which are defined as @helper bar() { /* markup */ } and are public for any view to use.

Also, in a regular Razor view I can write "private" helpers as such:

@functions {
  public IHtmlString foo() { return new MvcHtmlString("foo"); }
}

I would like to have "private" functions within my declarative helpers, OR, I would like to have "private" declarative helpers within my declarative helper files. The alternative is to write regular helper classes--but I prefer markup in this case as it's less verbose and easier to maintain.

Why would you want to do this? You have a view, and you want to pull in some markup; that's done by referencing a declarative helper. But that DH is in a file full of other DHs which use common markup. So you want to move all that commonality into a single place: a "private" declarative function/helper which only the DHs in that file can see.

0

There are 0 answers