ArcSet
ArcSet

Reputation: 6860

How to post a form and string to MVC 4 controller

Having problems sending multiple data over Post to MVC Controller No matter what step I send by post it isn't received by the controller and defaults to 1, but it will still send the form correctly.

public class SetupP{
    public string fn {get;set;}
    etc...
}

public ActionResult Start(int step = 1, Setup SetupP = null){
    if(step == 1)
    if(step ==2)
}



$.post("/setup/Start", { step: 2, SetupP: $('#SetupForm').serialize() }

Upvotes: 0

Views: 33

Answers (1)

Roamer-1888
Roamer-1888

Reputation: 19288

$('#SetupForm').serialize() returns a query string eg single=Single&check=check1&radio=radio1 (from jQuery's .seialize() example).

Therefore { step: 2, SetupP: $('#SetupForm').serialize() } would attempt to present an entire query string as the single parameter SetupP. It's a hybrid data format and won't work.

You can put the pieces together manually, like this :

$('#SetupForm').serialize() + '&step=2'

Or if the step value is available as a variable, then :

$('#SetupForm').serialize() + '&step=' + someVariable

Upvotes: 1

Related Questions