2

I am about to re-write all common MVC Html helpers to provide some localization abilities inside. I am trying to find a way not to ruin what actually current framework helpers doing on their own. For example; i want to re-write "LabelFor" html helper without changing what it actually does in the MVC framework, except only changing its "InnerHtml". Since framework helpers return "MvcHtmlString", i actually don't know how to play around with it.

public static class MvcLabelExtensions
{        
    public static MvcHtmlString Label(this HtmlHelper html, string expression)
    {
       MvcHtmlString baseResult = System.Web.Mvc.Html.LabelExtensions.Label(html, expression);
       // want to change InnerHtml here... ??? ..
       return baseResult;
    }
}
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
Noldor
  • 1,122
  • 9
  • 22
  • Try this post http://stackoverflow.com/questions/5196290/how-can-i-override-the-html-labelfor-template – naim shaikh Apr 30 '12 at 13:52
  • Does the built in localization via DataAnnotations not meet your needs? – Shawn C. Apr 30 '12 at 13:53
  • @naim shaikh -- I will do it in that way already. My actual concern is keeping what actual framework helpers doing and only changing InnerHtml after than.. – Noldor Apr 30 '12 at 14:16
  • @Shawn C. -- I am actually designing the project to work with database oriented localization. So there is a wcf service layer between client and database. I will get text translations via: View->HtmlHelper->MvcController->WcfService->BusinessLogic->Database. So, i think using DataAnnotations with Resources will not be enough. Only if i could implement a custom ResourceProvider or ResourceManager for this structure... but it seemed to me it is easier to make it in the HtmlHelpers since it is also suitable for Mvc structure. Right? – Noldor Apr 30 '12 at 14:24

0 Answers0