none
Model object is null after post in MVC RRS feed

  • Question

  • @model SSQWeb.Models.Reservations @{ ViewBag.Title = "New Audit - Reservation "; Layout = "~/Views/Shared/Master.cshtml"; } <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <meta name="viewport" content="width=device-width, intial-scale=1.0" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" /> <link rel="stylesheet" href="~/css/style.css" /> <script src="~/Scripts/bootstrap.min.js"></script> @using (Html.BeginForm("NewResAudit", "Reservations", FormMethod.Post, new { encType = "multipart/form-data", name = "myform", id = "myform" })) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <div id="tabs"> <ul> <li><a href=#AuditSheet>AuditSheet</a></li> <li><a href=#OR>Observations & Recommendations</a></li> </ul> <div id=AuditSheet> <h4 class="Passeneger-details">Reservations Audit Form</h4> <div class="table-responsive" style="padding-top: 0px; width: 100%"> <table id="tblStaffDetails" border="1" class="display table" style="width:100%"> <tr> <td style="text-align:left">@Html.LabelFor(model => model.AgentName)</td> <td style="text-align:left">@Html.EditorFor(model => model.AgentName) @Html.ValidationMessageFor(model => model.AgentName) </td> <td style="text-align:left">@Html.LabelFor(model => model.Date) </td> <td style="text-align:left">@Html.EditorFor(model => model.Date) @Html.ValidationMessageFor(model => model.Date) </td> </tr> <tr> <td style="text-align:left">@Html.LabelFor(model => model.RecordingId)</td> <td style="text-align:left">@Html.EditorFor(model => model.RecordingId) @Html.ValidationMessageFor(model => model.RecordingId) </td> <td style="text-align:left">@Html.LabelFor(model => model.Time) </td> <td style="text-align:left">@Html.EditorFor(model => model.Time) @Html.ValidationMessageFor(model => model.Time)</td> </tr> <tr> <td style="text-align:left">@Html.LabelFor(model => model.CallerNo)</td> <td style="text-align:left">@Html.EditorFor(model => model.CallerNo) @Html.ValidationMessageFor(model => model.CallerNo)</td> <td style="text-align:left">@Html.LabelFor(model => model.ObservedBy)</td> <td style="text-align:left">@Html.EditorFor(model => model.ObservedBy) @Html.ValidationMessageFor(model => model.ObservedBy)</td> </tr> </table> </div> <div class="table-responsive" style="padding-top: 0px;"> @for(int iql =0; iql < @Model.QuestionList.Count;iql++) { <div class="row"> <div class="col-md-12"> <h1 class="heading tableHeading">@Model.QuestionList[iql].Description</h1> </div> </div> <div class="table-responsive" style="padding-top: 0px;"> <table id="tblAuditQuestions" cellpadding="0" cellspacing="0" border="0" class="table"> <thead> <tr> <th>Sub-Parameters</th> <th>Rating</th> <th>Remarks</th> <th>Excellent</th> </tr> </thead> <tbody> @{ int j = 0; for (int iAe =0;iAe < @Model.QuestionList[iql].Audit_entries.Count; iAe ++) { j++; <tr> <td style="text-align:left"> @Model.QuestionList[iql].Audit_entries[iAe].Question</td> <td style="text-align:left"> @Html.DropDownListFor(n => @Model.QuestionList[iql].Audit_entries[iAe].Rating, @Model.QuestionList[iql].Audit_entries[iAe].Rating, new { @class = "form-control" }) </td> <td style="text-align:left"> @Html.EditorFor(model => @Model.QuestionList[iql].Audit_entries[iAe].Remarks, new { @class = "required" }) @Html.ValidationMessageFor(model => @Model.QuestionList[iql].Audit_entries[iAe].Remarks)</td> @if (@j == 1) { <td style="text-align:center;vertical-align:middle!important;" rowspan=@Model.QuestionList[iql].Audit_entries.Count()> @Html.TextAreaFor(model => @Model.QuestionList[iql].SectionExperience) @Html.ValidationMessageFor(model => @Model.QuestionList[iql].SectionExperience) </td> } </tr> } } </tbody> </table> </div> } </div> <br /> </div> </div> <p> <input type="submit" id="btnSubmit" value="Submit" /> </p>

       <script type="text/javascript">

     $(document).ready(function () {
                    $('#btnSubmit').click(function (e) {
                        debugger;
                        $.ajax({
                            url: '@Url.Action("NewResAudit", "Reservations",Model)',
                            dataType: 'html',
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            success: function (data) {
                            }
                        });
                    });
                });
                </script>

    In my controller :-

               

     [HttpPost]
            //
            public ActionResult NewResAudit(Reservations reservations)
            //public ActionResult NewResAudit(FormCollection  coll)
            {
                if (ModelState.IsValid)
                {
                    //Reservations _reservations = reservations;
                    return View();
                }

                return View();

            }

    i have written above code for getting submitted object of Reservations class.

    below is my model :-

    public class Reservations
    {
        public string AgentName { get; set; }   
        public DateTime Date { get; set; }
        public string RecordingId { get; set; }
        public string Time { get; set; }
        public string CallerNo { get; set; }
        public string ObservedBy { get; set; }
        public List<Audit_Question_Res> QuestionList { get; set; }
    }
    
    
    public class Audit_Question_Res
    {
        public string Description { get; set; }
        public string SectionExperience { get; set; }
        public List<Audit_entiry_Res> Audit_entries { get; set; }
    }
    
    public class Audit_entiry_Res
    {
        public string Question { get; set; }
        public string QuestionCode { get; set; }
        public IEnumerable<SelectListItem> Rating { get; set; }
        public string Remarks { get; set; }
    }

    every time 'reservations' object of my controller is blank after submit the details.

    please help me.



    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" /><link href="~/css/style.css" rel="stylesheet" />

    Anup_


    Friday, August 4, 2017 10:08 AM

All replies