I have a form send POST data to an action, so I creating an action with multiple parameters is a FormCollection and a string. But I don't know how to pass it into AJAX jQuery.
This is my action method:
public ActionResult Edit(FormCollection form, string CodeName)
{
List<Product> PList = (List<Product>)TempData["PListIndex"];
var index = PList.FindIndex(c => c.Code == CodeName);
PList[index].NameProduct = form[0];
PList[index].Price = form[1];
PList[index].Madein = form[2];
if (FileFactory.Save(PList, @"DATA\CSDL.DAT"))
return Json("Success", JsonRequestBehavior.AllowGet);
return Json("Failed to Save", JsonRequestBehavior.AllowGet);
}
This is my Ajax jQuery:
function sendformdata() {
var form = $("#Edit").serialize();
$.ajax({
type: "POST",
url: '@Url.Action("Edit", "FileEx")',
data: { form: form, CodeName: _codename } // I don't know how to pass these two parameters
success: function (response) {
alert(response);
}
});
}
FormCollection