Question

I have a web page with some static controls (defined in server) and dynamic controls, (created by JavaScript). How can I get the data from both static and dynamic controls in the controller on form post?

All my search leads to use JSON with AJAX. But I am looking for how to pass JSON on form submit. I want to navigate to different page with relevant data after successful submit. Is it possible to return to a different view (in the controller) when the page is posted through AJAX? Is there any other options available?

No correct solution

OTHER TIPS

I guess that the dynamic controls you are injecting into your form represent input elements that have specific names. If they don't then you probably should consider changing your code so that the dynamic controls you are inserting have names. You might take a look at the following article for an example: http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/

Once you have all the elements inside the form, submitting it is just a matter of the user clicking on the submit button. Your controller action will receive a view model with all the properties. And if you want to use AJAX and still redirect, you could set the window.location.href property inside your AJAX success callback to the desired url you are willing to redirect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top