Skip to content Skip to sidebar Skip to footer

Custom Html Helpers In Asp.net Mvc 2

I want to create a pagination helper. The only parameters that it needs are currentpage, pagecount and routename. However, I do not know if it is possible to use the return value o

Solution 1:

Generally, yes you can use the results of other Html Helper functions within your custom functions. The exception would be any that write directly to the response stream rather than returning a string value.

I've done this sort of thing several times myself, and it works just fine...here's a sample I just totally made up right now based on something I did that I don't have the code for handy right now:

publicstaticstringRssFeed(this HtmlHelper helper, string url)
{
    StringBuilder sb = new StringBuilder();
    sb.Append(GetRSSMarkup(url));  // This generates the markup for the feed data
    sb.Append(helper.ActionLink("Go Home","Index","Home"));
    return sb.ToString();
}

Post a Comment for "Custom Html Helpers In Asp.net Mvc 2"