MVC:通过 JQuery 从视图传递模型

发布于 2024-12-20 02:39:06 字数 295 浏览 3 评论 0原文

我认为我传递给它的模型如下:

    @model DB.Models.Employees

用户更新模型后,我喜欢通过 Jquery 传递模型。 我有以下代码 - 请注意 url 是我的控制器的路径:

     $.post(url, { employeeinfo: '@Model' },
     .....

@Model 没有传递整个模型。当我在控制器中查看它的内容时,我得到一个空值。

我正在使用 MVC .NET

I have the following model in my view that I am passing to it:

    @model DB.Models.Employees

after the user updates the model, I like to pass the model through Jquery.
I have the following code - note that url is the path to my controller:

     $.post(url, { employeeinfo: '@Model' },
     .....

@Model did not pass the whole model. I get a null value when I view the content of it in the controller.

I am using MVC .NET

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好听的两个字的网名 2024-12-27 02:39:06

您必须获取模型值并将它们放入 JSON 对象中。然后它会将您的模型发送到服务器。

    var emp = {
        SearchType: $('#txtFirstName').val(),
        SelectedAccounts: $('#txtLastName').val()
    };

    $.ajax({
        url: "UpdateEmp",
        data: parms,
        type: "POST",
        dataType: 'json',
        success: function (data) {

        },
        error: function () {
            document.location = 'ErrorThrown';
        }

这是一篇关于在发送后将您的模型绑定到您的模型的好文章。
模型绑定

You have to get the model values and put them in a JSON object. Then it will send your model to the server.

    var emp = {
        SearchType: $('#txtFirstName').val(),
        SelectedAccounts: $('#txtLastName').val()
    };

    $.ajax({
        url: "UpdateEmp",
        data: parms,
        type: "POST",
        dataType: 'json',
        success: function (data) {

        },
        error: function () {
            document.location = 'ErrorThrown';
        }

Here is a good article on binding your to your model after it is sent.
model binding

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文