[英]Getting Null value while Passing Model Property to a function in ASP.Net MVC
I have an array inside javascript for storing all field values and am passing that array to a model property AddChecklistSurveyResult
. 我在javascript中有一个数组,用于存储所有字段值,并将该数组传递给模型属性
AddChecklistSurveyResult
。 After submitting the page am trying to pass this model property as a parameter inside a function SaveLpgResult
while calling service, It's showing Null, Thanks in advance. 提交页面后,尝试在调用服务时将此模型属性作为参数传递给函数
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
}
Am Expecting result like this: 我期待这样的结果:
[
{
"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
}
]
Finally, I solve the problem. 最后,我解决了这个问题。 Added an onclick event inside the button for calling the javascript function
在按钮内添加了onclick事件,用于调用javascript函数
<button type="submit" class="btn btn-success" onclick="LpgChecklist()">Save</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.