我試圖通過使用ajax JQuery
我的模型值從視圖傳遞到控制器。在我的控制器中,該模型顯示爲null
。傳遞模型從視圖到控制器與JQuery的Ajax
控制器已經從ajax方法調用,但問題是控制器中的對象顯示爲null
。
這是模型的結構簡單:
public class Invoice
{
public Invoice(InvoiceHeader invHeader, List<InvoiceItems> InvItmem)
{
this.invHeader = invHeader;
this.InvItmem = InvItmem;
}
public InvoiceHeader invHeader { get; private set; }
public List<InvoiceItems> InvItmem { get; private set; }
}
這是控制器的結構:
[HttpPost]
public ActionResult InsertItems(List<Invoice> invoice)
{
//List<InvoiceItems> asd = new List<InvoiceItems>();
//asd = invoice.();
return Json(true, JsonRequestBehavior.AllowGet);
}
這是查看:
@model BeetaTechModel.Invoice
@{
ViewBag.Title = "Index";
var val = Json.Encode(Model);
}
<h2>Index</h2>
<script type="text/javascript">
$(document).ready(function() {
$("#btnSubmit").click(function() {
// var val = Json.Encode(Model);
var check = @Html.Raw(val);
$.ajax({
type: 'POST',
url: "Invoice/InsertItems",
data: '{info:' + JSON.stringify(check) + '}' ,
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (data) {
alert(data);
}
});
});
});
</script>
@{Html.RenderPartial("InvoiceHeader", Model.invHeader);}
@{Html.RenderPartial("InvoiceItems", Model.InvItmem);}
<input type="submit" id="btnSubmit" value="Log In" />
反序列化什麼是AJAX的成功過程中驚動了數據? – Aditya