繁体   English   中英

Ajax:将模型列表传递给控制器

[英]Ajax: Pass Model List to Controller

我有一个将模型列表作为模型的视图,所以

 @model List<Collections.Models.Status>

我想将此列表作为Ajax调用的数据传递,但是我一直在获取“ System.Collections.Generic.List [Collections.Models.Status]”而不是模型中的值。

这是Ajax代码:

$.ajax({
        url: "/Home/Update",
        data: JSON.stringify(@Model),
        type: 'POST',
        dataType: 'json',
        success: function (responseJSON) {
            if (responseJSON.message == 'success') {
                alert('here');
            }
        },
        error: function (error) {
            showModal("Error: " + error.message);
        }
    }); 

在调试器中将其转换为:

$.ajax({
        url: "/Home/Update",
        data: JSON.stringify(System.Collections.Generic.List`1[Collections.Models.CollectionStatus]),
        type: 'POST',
        dataType: 'json',
        success: function (responseJSON) {
            if (responseJSON.message == 'success') {
                alert('here');
            }
        },
        error: function (error) {
            showModal("Error: " + error.message);
        }
    });

如何传递列表的实际值而不是System.Collections.Generic.List [Collections.Models.Status]?

我尝试了@ Model.ToList(),@ Html.Raw(Model),但都没有用。

将contentType属性设置为application / json。 并使用下面的代码设置数据属性

data: JSON.stringify({'your controllers parameter name': '@Model'})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM