MVC4 Ajax-通完整的模型控制器控制器、模型、完整、Ajax

由网友(﹏粉黛佳人ゞ)分享简介:我有我的AJAX调用$.ajax({type: 'post',url: "/Store/LoadStoreIndex",data: , //Entire Model Here!!dataType: "text",success: function (result) {$('#Postback').html(resul...

我有我的AJAX调用

$.ajax({
    type: 'post',
    url: "/Store/LoadStoreIndex",
    data: , //Entire Model Here!!
    dataType: "text",
    success: function (result) {
        $('#Postback').html(result);
    }
});

我需要把我的整个模型反馈给控制器,但经过一番搜索找不到什么......谁能告诉我什么,我需要做?

I need to send my entire model back to the controller, but after much searching can't find anything ... Can somebody show me what I need to be doing?

推荐答案

控制器获取行动

public ActionResult Index(YourModel model)
{
    YourModel model = new YourModel();

    return View(model);
}

查看

@model YourModel
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "form1" }))
{
    @Html.TextBoxFor(x => x.EmailAddress)
    @Html.TextBoxFor(x => x.Name)
    ...
}

剧本

$(function () {
    $('form').submit(function () {
        if ($(this).valid()) {
            $.ajax({
                url: this.action,
                type: this.method,
                // you can post your model with this line
                data: $(this).serialize(),  
                beforeSend: function () {

                },
                complete: function () {

                },
                success: function (result) {

                },
                error: function () {

                }
            });
        }
        return false;
    });
});

控制器POST操作

Controller Post Action

[HttpPost]
public ActionResult Index(YourModel model)
{
    return View();
}
阅读全文

相关推荐

最新文章