0

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?

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

4 Comments

I get "A using namespace directive can only be applied to namespaces; 'Storyboard.Helpers.DetailsForm' is a type not a namespace"
So I tried using just Storyboard.Helpers but then it goes back to complaining that "The name 'LabelAndData' does not eixst in the current context".
If this still doesn't help, it would be helpful if you post the code to your helper, including namespace and class..
Yes, that works. I couldn't refer to it properly as an extension to Html before, hence the passing it as the first parameter, but now it works. Thanks!
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.