2

We need validation attributes on and no HtmlHelper is provided in this respect.

So we started developing a new helper.

To find out how, we looked over the MS code by using JetBrains dotPeek and found everything we need in InputExtensions.cs from System.Web.Mvc (4.0).

There is a problem: for creating input helpers we need to use InputHelper() method which is unfortunately private.

Why is private? This should be a good extension point for input helpers.

So now we need to duplicate this code in our case to provide functionality for creation of with template ing, validation attributes, ....

Do you think that what we are doing is correct?

Is there a page in the documentation that says how to do extension methods of this kind?

P.S. found some implementations but they are not quite what I want: http://blog.isilverlabs.com/2011/01/mvc-file-input-helper/

radu florescu
  • 4,315
  • 10
  • 60
  • 92
  • Have you seen [this Microsoft page(Creating HTML-Helper)](http://www.asp.net/mvc/tutorials/older-versions/views/creating-custom-html-helpers-cs) ? – developer10214 Oct 18 '13 at 09:18
  • I know how to create one, but I need the support of input helper which is both private and inaccessible. – radu florescu Oct 18 '13 at 09:21
  • Maybe [this NuGet-Package ASP.NET Web Helpers Library](http://www.nuget.org/packages/microsoft-web-helpers/) helps you with its FileUpload-Helper. – developer10214 Oct 18 '13 at 09:39
  • Have you read the question? I need it for MVC. In the page you linked look at this message: This package is not compatible with ASP.NET MVC. – radu florescu Oct 18 '13 at 09:40
  • You're right there is such a line, I didn't noticed it before. Nevertheless, I use this package since month in serveral MVC4 application without any problems (e.g. the @Video helper). Maybe they forgot an MVC Version number, like MVC2 or MVC2, because it references some libraries which are may not available in earlier versions of MVC. – developer10214 Oct 18 '13 at 09:53

1 Answers1

1

Custom field templates may be what you're looking for. They'll allow you to overwrite the html that is generated when you call @Html.EditorFor() or @Html.DisplayFor().

Mark the property on your view model with the UIHint attribute, providing your custom template name.

The HtmlHelper extension methods will automatically look for a matching template in the DisplayTemplates or EditorTemplates folder.

Here's a similar StackOverflow question: How to create custom editor/display templates in ASP.NET MVC 3?

Community
  • 1
  • 1
Sambo
  • 1,472
  • 5
  • 21
  • 33