jsからコントローラーに保存するためのビューモデルデータを次のように渡しています
$(function () {
$.ajax({
url: "/api/BranchSurvey/GetBranchLogicConditions?qId=" + questionId + "&isAdd=false",
success: function (branchLogicdata) {
BrSViewModel = ko.mapping.fromJS(branchLogicdata);
$.ajax({
url: "/api/BranchSurvey/BranchingLogicQuestion?questionId=" + questionId,
success: function (branchLogicQuestion) {
BrSViewModel.Question = branchLogicQuestion;
ko.applyBindings(BrSViewModel, document.getElementById('mainDiv'));
}
});
}
});
$("#btnSaveLogic").click(function () {
debugger;
$.ajax({
url: "/api/BranchSurvey/SaveBranchLogicConditions",
type: 'post',
data: ko.toJSON(BrSViewModel),
success: function (data) {
branchingSurveyPopupBody.empty();
branchingSurveyPopup.dialog('destroy');
}
});
return false;
});
});
コントローラ内
public class BranchSurveyController : ApiController
{
[HttpPost]
public void SaveBranchLogicConditions(BranchLogic objBranchSurvey)
{
string str = "<condition>";
string qstText = "";
int count = 0;
foreach (BranchCondiotionXml oxml in objBranchSurvey.ListBranchXML)
{
..... (something)
}
}
}
ブラウザでスクリプトをデバッグすると、 viewmodel で値を取得していますBrSViewModel
。しかし、コントローラーに行くと、すべてのデータが空になります。
私のエンティティは
public class BranchLogic
{
#region private members
List<BranchCondiotionXml> lstBranchXML = new List<BranchCondiotionXml>();
Question _question = new Question();
string targetQuestionCondition = string.Empty;
string thenTargetQuestion = string.Empty;
string sucessQuestion = string.Empty;
string thenTargetUrl = string.Empty;
string elseTargetQuestionCondition = string.Empty;
string elseTargetQuestion = string.Empty;
string elseSuccessQuestion = string.Empty;
string elseTargetUrl = string.Empty;
#endregion
#region public members
public List<BranchCondiotionXml> ListBranchXML
{
get { return lstBranchXML; }
set { lstBranchXML = value; }
}
public Question Question
{
get { return _question; }
set { _question = value; }
}
public string TargetQuestionCondition
{
get { return targetQuestionCondition; }
set { targetQuestionCondition = value; }
}
public string ThenTargetQuestion
{
get { return thenTargetQuestion; }
set { thenTargetQuestion = value; }
}
public string SucessQuestion
{
get { return sucessQuestion; }
set { sucessQuestion = value; }
}
public string ThenTargetUrl
{
get { return thenTargetUrl; }
set { thenTargetUrl = value; }
}
public string ElseTargetQuestionCondition
{
get { return elseTargetQuestionCondition; }
set { elseTargetQuestionCondition = value; }
}
public string ElseTargetQuestion
{
get { return elseTargetQuestion; }
set { elseTargetQuestion = value; }
}
public string ElseSuccessQuestion
{
get { return elseSuccessQuestion; }
set { elseSuccessQuestion = value; }
}
public string ElseTargetUrl
{
get { return elseTargetUrl; }
set { elseTargetUrl = value; }
}
#endregion
}
どこが間違っているのか教えてください。前もって感謝します。