asp.net mvc 4 - MVC4 Ajax- Pass complete model to controller -
i have ajax call
$.ajax({ type: 'post', url: "/store/loadstoreindex", data: , //entire model here!! datatype: "text", success: function (result) { $('#postback').html(result); } });
i need send entire model controller, after much searching can't find ... can show me need doing?
controller action
public actionresult index(yourmodel model) { yourmodel model = new yourmodel(); homecoming view(model); }
view
@model yourmodel @using (html.beginform("index", "home", formmethod.post, new { id = "form1" })) { @html.textboxfor(x => x.emailaddress) @html.textboxfor(x => x.name) ... }
script
$(function () { $('form').submit(function () { if ($(this).valid()) { $.ajax({ url: this.action, type: this.method, // can post model line data: $(this).serialize(), beforesend: function () { }, complete: function () { }, success: function (result) { }, error: function () { } }); } homecoming false; }); });
controller post action
[httppost] public actionresult index(yourmodel model) { homecoming view(); }
ajax asp.net-mvc-4
No comments:
Post a Comment