我正在使用 jQuery 进行 AJAX 调用:
var topic = new Array();
$('.container-topico').each(function (i) {
topic.push(
{
"TopicsModel":
{
begins: $(this).find('.HoursStart').val(),
ends: $(this).find('.HoursEnd').val(),
texts: $(this).find('.input-topic').val()
}
}
);
});
var data = JSON.stringify({
videoId: '<%=Url.RequestContext.RouteData.Values["id"]%>',
topics: topic
});
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: '<%= Url.Action("SubmitTopics") %>',
traditional: true,
data:
data
,
beforeSend: function (XMLHttpRequest) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
},
success: function (data, textStatus, XMLHttpRequest) {
$(data).each(function () {
});
}
});
它以以下格式发送 JSON(例如):
{"videoId":"1","topics":
[{"TopicsModel": {"begins":"00:00:33","ends":"00:01:00","texts":"1. Primeiro tema"}},
{"TopicsModel": {"begins":"00:01:00","ends":"00:01:33","texts":"2. Segundo tema"}},
{"TopicsModel": {"begins":"00:01:33","ends":"00:02:00","texts":"3. Terceiro tema"}},
{"TopicsModel": {"begins":"00:02:00","ends":"00:00:21","texts":"dasdasdsa ada as das s"}},
{"TopicsModel": {"begins":"0","ends":"0","texts":""}}]}
在服务器端它有模型:
public class TopicsModel
{
public string begins;
public string ends;
public string texts;
}
和控制器:
public ActionResult SubmitTopics(int videoId, List<TopicsModel> topics)
发生的事情是:
它具有正确数量的对象,但没有绑定每个元素的属性,如下所示:
为什么它不绑定到属性?