0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

How do I get the validation function to call? For example, the required attribute will add data-val-required to the input. When building my own custom HtmlHelper, how do I know what attribute has been set on the input?
@Extrakun - Won't you be setting it yourself using the Tag Builder? Maybe I'm not following completely, have you started on some code that you can show?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.