私は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)
何が起こるか:
以下に示すように、正しい数のオブジェクトがありますが、各要素のプロパティをバインドしていません。
プロパティにバインドしないのはなぜですか?