我在javascript中有一个数组,用于存储所有字段值,并将该数组传递给模型属性AddChecklistSurveyResult
。提交页面后,尝试在调用服务时将此模型属性作为参数传递给函数SaveLpgResult
内的函数,它显示为Null,预先感谢。
public string AddChecklistSurveyResult { get; set; }
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<table>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-success">Save</button>
</td>
</tr>
</table>
@Html.HiddenFor(model => model.AddChecklistSurveyResult);
}
function LpgChecklist()
{
$.each(answers, function (index, value) {
surveyIdList = surveyIdObj
surveyTemplateList = surveyTemplateObj
answerList = value.answerListId;
question = value.questionId;
value = value.value;
ChecklistDetails.push({
answerArr: answerList,
QuestionArr: question,
valueArr: value
});
console.log(ChecklistDetails);
$("#AddChecklistSurveyResult").val(JSON.stringify(ChecklistDetails));
});
[HttpPost]
public ActionResult _QAGInspectionDetails(QAGInspectionViewModel model)
{
var save = qAGCaseService.Create(model);
}
public bool Create(QAGInspectionViewModel model)
{
SaveLpgResult(model.AddChecklistSurveyResult, model.EntryBy);
//Here Am getting Null for model.AddChecklistSurveyResult
}
我期望这样的结果:
[
{
"LPG_Brand":"Caltex",
"LPG_Status":null,
"LPG_Capacity":"13.3",
"LPG_Used":"",
"LPG_Unused":"",
"LPG_Quantity":"",
"LPG_Detained":"Yes",
"LPG_StorageLocation":"EMSD",
"LPG_Brand_Display":null,
"LPG_Capacity_Display":null,
"LPG_Detained_Display":null,
"LPG_StorageLocation_Display":null
}
]
答案 0 :(得分:0)
最后,我解决了这个问题。在按钮内添加了一个onclick事件,用于调用javascript函数
<button type="submit" class="btn btn-success" onclick="LpgChecklist()">Save</button>