ASP NET MVC: Dynamically adding or removing inputs on the form - unobtrusive validation?

I don't think it is possible using the default unobtrusive libraries supplied. If you look at jquery.validate. Js and jquery.validate.unobtrusive.

Js it looks like it only validates what is inside the form.

I don't think it is possible using the default unobtrusive libraries supplied. If you look at jquery.validate. Js and jquery.validate.unobtrusive.

Js it looks like it only validates what is inside the form. There's a few posts about it if Googled and a few work arounds. I had a similar issue (although much simpler) where I had a validation summary at the top of the page and multiple forms but the unobtrusive javascript would only populate the view summary if its inside the form (jquery.validate.unobtrusive.

Js line 39 if interested...). I'm not sure if the validation library is extendible but most things in jquery are so that might be an option if you want to go down that road. As far a possible solution to your problem I'll put in my 2 cents for whats its worth.

You could have two actions that are posted to. The first action is you post your model with no js validation and all validation is handled in the code - this will catch all user with javascript turned off. Your second action is you serialized the model.In mvc 3 using the Ajax.

BeginForm has an AjaxOption for Url where you can specify an action for the jquery to call (where it serializes the form form you and you can decorate your action with your strongly typed model). Here you can check the model and return a json result and handle this in the javascript.

Thanks for your comment. Well, I am even not at the point of javascript yet, MVC does not even generate the data-... attributes on the inputs. Also I could not see how your workarounds could help me.

– Aliostad Feb 4 at 14:37 Do you have and set in the web. Config and references to the javascript library? As it should generate the data- attributes for you.It will only create the data- attributes if its within the form and if you've specified validation attributes like Required and StringLength etc. – Simon G Feb 4 at 15:22 If you are adding form elements using javascript/jquery you can always add data- elements manually.

If you look at how mvc generates them and copy that method. I think the validation uses the "live" option is jquery so any you add this way should be picked up. – Simon G Feb 4 at 15:24.

Short Answer: Add this to the partial view: if (ViewContext. FormContext == null) { ViewContext. FormContext = new FormContext(); }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions