I am writing application with asp.net mvc. I have controller with action, which use some ViewModel as parameter. How to send form data with jquery post to that mvc controller.
I am writing application with asp.net mvc. I have controller with action, which use
Share
Your ViewModel Property names and Parameter we are passing should be same. Ie : Your view model should have 2 properties called
FirstNameandLastNamelike hisAnd your Post action method should accept a parameter of type
PersonViewModelAlternatively, If your view is strongly typed to the PersonViewModel, you can simply send the serialized form to the action method using jQuery
serializemethodEDIT : As per the comment
Serializewill take care of the Child property as well. Assume you have a class called Profession like thisAnd your PersonViewModel has a property of type
ProfessionYou will get these data in your HttpPost Action method, if you fill that from your view.