开发者

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

开发者 https://www.devze.com 2023-02-20 00:59 出处:网络
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 cont

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 ho开发者_运维技巧w the unobtrusive data tags are added.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号