Custom HTML Helpers in ASP.NET MVC 2

Posted by Interfector on Stack Overflow See other posts from Stack Overflow or by Interfector
Published on 2010-06-13T15:42:04Z Indexed on 2010/06/13 15:52 UTC
Read the original article Hit count: 448

Filed under:
|

Hi, 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 of another html helper inside the definition of my html helper. I am referring specifically to Html.RouteLink. How can I go about doing something like this in the class definition

using System;
using System.Web.Mvc;

namespace MvcApplication1.Helpers
{
     public static class LabelExtensions
     {
          public static string Label(this HtmlHelper helper, string routeName, int currentpage, int totalPages)
          {
               string html = "";
               //Stuff I add to html
               //I'd like to generate a similar result as the helper bellow
               html .= Html.RouteLink( pageNo, routeName, new { page = pageNo - 1 } );
               //Other stuff I do the html
               return html;

          }
     }
}

Thank you.

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about htmlhelper