0

我有我的 AJAX 电话

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

我需要将整个模型发送回控制器,但经过大量搜索后找不到任何东西......有人可以告诉我我需要做什么吗?

4

1 回答 1

3

控制器获取操作

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;
    });
});

控制器发布操作

[HttpPost]
public ActionResult Index(YourModel model)
{
    return View();
}
于 2013-02-07T20:16:52.993 回答