开发者

ASP.NET MVC Referencing Html Helper from a view

开发者 https://www.devze.com 2023-02-15 13:52 出处:网络
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:

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 b开发者_如何学Goe allowed in the ascx file. Is there an equivalent?


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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消