1

I just ported my application to mvc3 and i have a lot of view using jquery form plugins. I would like to use the unobtrusive jquery validation provided by MVC3 but i dont want to use Ajax.BeginForm or Html.BeginForm. Is there a way of having the html5 tag rendered alone ?

1 Answer 1

1

Well, from a quick search in the source... You can't without hacking around a bit. At least not from the server side.

From what I understand the unobtrusive validation uses the Data-* attributes rendered for each input when using the helpers, and only when a FormContext exists in the ViewContext.

You could create a FormContext in the ViewContext yourself (if you're using EditorFor), it might work. This.ViewContext.FormContext = new FormContex() might work.

As an alternative you can call @Html.GetUnobtrusiveValidationAttributes() and do it yourself, but I think that this with this kind of refactoring using @Html.BeginForm() and Html.EditorFor() is easier.

Basically, it's more trouble than its worth, at least server side. Especially if you've already got validation running.

Maybe looking in the actual source of the unobtrusive JS is a better option, but that's out of my scope. Maybe someone else can help some more...

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

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.