Extrakun
Extrakun

Reputation: 19305

MVC3 - Coding a custom HTML Helper which output works with unobtrusive Javascript

I am attempting to add unobtrusive JavaScript to a file upload input control, using a custom HTML Helper extension. However, I have checked various blogs which use different methods to create the control, such as tab-builder but I couldn't find out how the unobtrusive data tags are added.

Upvotes: 0

Views: 743

Answers (2)

Paul Hiles
Paul Hiles

Reputation: 9778

If you are using TagBuilder, you can do this:

var validationAttributes = html.GetUnobtrusiveValidationAttributes(name, metadata);

then use MergeAttributes on your tagbuilder to add the unobtrusive validation attributes to your tag.

Upvotes: 0

Sergi Papaseit
Sergi Papaseit

Reputation: 16184

Unobtrusive data tags mainly means using the HTML 5 extensible "data-" attribute.

Check this blog post of Brad Wilson about unobtrusive javascript in MVC 3, he describes the various attributes used by the unobtrusive framework.

Upvotes: 1

Related Questions