我的jQuery Ajax調用。如何將模型從動作返回到ajax並傳遞給另一個動作。將模型傳遞給jquery ajax成功調用
function ChangeName(id)
{
var name=$("#name").val();
$.ajax({
cache:false,
url: "@Url.Action("EditName", "Order")",
data: "Name=" +name+"&Id="+id ,
type: "POST",
success: function (data) {
window.location.href=data.Url;//doesnt work passes null model
}
});
}
public ActionResult EditName(string name,int id)
{
var product= GetProduct(id);
product.Name=name;
UpdateProduct(product);
var model=new ProdModel(){id=id};
return Json(new
{
Url = Url.Action("Test","Order",new{model=model})
},JsonRequestBehavior.AllowGet);
}
public ActionResult Test(ProdModel model)//Model null
{
return RedirectToAction("List", "Product");
}
我試過這個,但沒有得到成功。
當'Test'行爲期待'OrderModel'時,Your're正在傳遞'ProdModel'。 – haim770
@ haim770更正! –