Dan
Dan

Reputation: 7

ASP.NET MVC Referencing Html Helper from a view

I've written an Html Helper called DetailsForm to reduce repetition when displaying fields in a view. Within a view - actually a partial view, ascx file - I can refer to it like this:

Storyboard.Helpers.DetailsForm.LabelAndData(Html, m => m.id)

But would like to refer to it like this:

LabelAndData(Html, m => m.id)

A 'using' directive doesn't seem to be allowed in the ascx file. Is there an equivalent?

Upvotes: 0

Views: 429

Answers (2)

Yngve B-Nilsen
Yngve B-Nilsen

Reputation: 9676

you should be able to import the namespace in the top of your ascx, like so:

<%@ Import Namespace="Storyboard.Helpers" %>

UPDATE

Reading your comment, I'm guessing your helper looks something like:

public static Something LabelAndData(this HtmlHelper html, .....

in which case you would call it like this in your view:

Html.LabelAndData(m => m.id)

Hope that helps!

Upvotes: 1

rob waminal
rob waminal

Reputation: 18419

if you use the same namespace as the Default Html Helpers which is System.Web.Mvc.Html of MVC for the one that you created, you don't need to reference your created Html Helper anywhere.

Upvotes: 0

Related Questions