У меня есть форма для отправки данных POST к действию, поэтому я создаю действие с несколькими параметрами: FormCollection
и строка. Но я не знаю, как передать это в AJAX jQuery.
Это мой метод действия:
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);
}
Это мой 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);
}
});
}