This is my action method which is supposed to receive a customer object and a string of json, I need both to be posted in same Action Method however,
public ActionResult CreateNewCustomer(Customers customers, string model)
{
//....Codes omitted
}
I tried posting using AJAX like here,
$.ajax({
type: "POST",
url: url,
data: { customers: $("#formtopost").serialize(), model: JSON.stringify(jsonToPost) },
success: function (data) {
alert(data);
}
});
e.preventDefault();
But with this approach The customers object is always being null, Either I have to exclude model string or customers object. Please help me how can I receive both in same Action Method like mentioned above.
Any suggestions will be appreciated.
customertocustomers[HttpPost]for your action method.modelstring but onlycustomersis null.[HttpPost]does. You only need this if there are other methods with the same name and in that case you want to add[HttpGet]to the get methods. To save you looking it up, the[HttpPost](get/delete/etc) attributes limit the action to that verb, they do not say it's a post method - it's always a post method unless there's a restriction on it.