Asp.net mvc 默认模型绑定器能否生成IEnumerable<;FormItem>;?
服务器: 如何使用默认模型绑定器将ajax数据转换为强类型IEnumerableAsp.net mvc 默认模型绑定器能否生成IEnumerable<;FormItem>;?,asp.net-mvc,Asp.net Mvc,服务器: 如何使用默认模型绑定器将ajax数据转换为强类型IEnumerable $(function() { $('#myform').submit(function() { var form = $(this); $.ajax({ url: form.attr('action'), type: form.attr('method'), data: form.serialize(),
$(function() {
$('#myform').submit(function() {
var form = $(this);
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
success: function(result) {
}
});
});
});
假设
MyClass
是这样的
[HttpPost]
public JsonResult Save(FormItems data)
您的html应该如下所示(请注意,每个值输入的名称的前缀是FormItems
中匹配的可枚举属性名称)
好啊
这完全取决于您在视图中的结构。你能从你的视图发布HTML吗?
$(function() {
$('#myform').submit(function() {
var form = $(this);
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
success: function(result) {
}
});
});
});
[HttpPost]
public JsonResult Save(FormItems data)
public class MyClass
{
public string Value { get; set; }
}
< form id="myform" action="/" method="post">
<!-- Those inputs could be added dynamically -->
<input type="text" name="Values[0].Value" />
<input type="text" name="Values[1].Value" />
<input type="text" name="Values[2].Value" />
<input type="text" name="Values[3].Value" />
<button type="submit">OK</button>
</form>