简体   繁体   English

在将模型属性传递给ASP.Net MVC中的函数时获取Null值

[英]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,预先感谢。

MODEL (QAGInspectionViewModel ) 模型(QAGInspectionViewModel)

public string AddChecklistSurveyResult { get; set; }

HTML 的HTML

    @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);
}

JAVASCRIPT JAVASCRIPT

 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));

            });

CONTROLLER 控制器

[HttpPost]
public ActionResult _QAGInspectionDetails(QAGInspectionViewModel model)
{
    var save = qAGCaseService.Create(model);
}

qAGCaseService (SERVICE) qAGCaseService(SERVICE)

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.

相关问题 在ASP.NET MVC中将模型数据传递给JSON(返回null) - Passing Model Data to JSON in ASP.NET MVC (returning null) 检查Asp.Net Mvc中来自Model的属性在JavaScript函数中是否不为null - Check if property from Model in Asp.Net Mvc is not null in javascript function 将ASP.NET MVC模型传递给Javascript函数 - Passing asp.net mvc model into Javascript function ASP.NET MVC 5-模型值未正确传递 - ASP.NET MVC 5 - model value not getting passed correctly 如果会话中的属性不为null或默认值,请运行/打印javascript Razor ASP.NET MVC - If property at session not null or default value, run/print javascript Razor ASP.NET MVC ASP.NET MVC dropdownlist级联错误无法将属性“值”设置为null - Asp.net mvc dropdownlist cascading error Cannot set property 'value' of null Asp.net MVC中的jquery验证错误 - 无法获取属性&#39;call&#39;的值:object为null或undefined - jquery validation error in Asp.net MVC - unable to get value of property 'call' : object is null or undefined 如果asp.net mvc中的模型不为null,如何从加载视图中调用jquery函数? - How do i call jquery function from the view on load if model is not null in asp.net mvc? 将Java语言变量作为模型传递给ASP.NET MVC中的PartiaView - Passing a Javascript variable as model for a PartiaView in ASP.NET MVC 视图未将模型传递给控制器​​-ASP.Net MVC - View is not passing the model to controller - ASP.Net MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM