Partial view is return NULL on POSTBACK

159 views Asked by At

My partial view is returning Null on submitting the form The main view is not null, it contains values on the form submission, I'm using render partial to include the partial view. Passing the model to partial view as well, tried passing the model in partial view action result as well but the result was the same. Any help would be highly appreciated Thanks

View

  ```  <div class="container">
            @using (Html.BeginForm("Menu", "Booking", FormMethod.Post))
            {
                @Html.AntiForgeryToken()
    
                <fieldset class="scheduler-border">
                    @*<div id="">
                            <input type="text" id="checkduplication" style="background: white; outline: none; border: none; border-color: transparent; color: red; font-weight: bold;" disabled />
                        </div>*@
    
    
                    <div class="form-group row">
                        @Html.HiddenFor(model => model.MenuID)
    
    
    
    
                        <label class="control-label col-sm-2"> Menu Name </label>
                        <div class="col-sm-4">
    
                            @Html.TextBoxFor(model => model.MenuName, new { @class = " form-control", @id = "FunctionName" })
                            @Html.ValidationMessageFor(model => model.MenuName)
                        </div>
    
    
                        <label class="control-label col-sm-2"> Menu Price </label>
                        <div class="col-sm-4">
    
                            @Html.TextBoxFor(model => model.MenuPrice, new { @class = " form-control", @id = "FunctionName" })
                            @Html.ValidationMessageFor(model => model.MenuPrice)
                        </div>
    
                    </div>

            <div id="MyPartialContainer">

                @if (Model.MenuItems != null)
                {
                    foreach (var x in Model.MenuItems)
                    {
                        { Html.RenderPartial("menuitems", x); }

                    }
                }


            </div>



            <div class="row" style="float: right">
                <input type="submit" id="submit" title="Save" value="Save" class="btn-success btn-lg" />
                <input type="button" onclick="window.location.reload();" id="cancel" title="Cancel" value="Cancel" class="btn-cancel btn-lg" />
                <br /> <br />
            </div>
        </fieldset>

    }
</div> ```

Model Classes

```  public class VMMenu
    {
        public VMMenu()
        {
            MenuItems = new List<VMMenuItems> { new VMMenuItems() };
           
        }
        public int MenuID { get; set; }
        public string MenuName { get; set; }
        public string MenuPrice { get; set; }
        //public int BookingDetailID { get; set; }
        //public int PaymentDetailID { get; set; }
        public IList<VMMenuItems> MenuItems { get; set; }
    }
    public class VMMenuItems
    {
        public int MenuItemID { get; set; }
        public int? MenuID { get; set; }
        public string ItemName { get; set; }
        public string ItemPrice { get; set; }
        public int? ItemCategory { get; set; }
        public string ItemCategoryName { get; set; }
    } ```

Action Methods

 public ActionResult Menu() {
            VMMenu menu = new VMMenu();
                      
            return View(menu);
        }
        [HttpPost]
        public ActionResult Menu(VMMenu _MenuDetails)
        {
            if (ModelState.IsValid)
            {
                VMMenu VMMenu=new VMMenu();
               
                Mapper.CreateMap<VMMenu,Menu>();
                Mapper.CreateMap<VMMenuItems,MenuItem>();
                Menu obj = Mapper.Map<VMMenu, Menu>(_MenuDetails);

                BookingRepo _repo = new BookingRepo();
                _repo.CreateMenu(obj);
                return View();                
                            }
            return View();
        }
        public ActionResult menuitems() 
        {
    
            return PartialView();
        } 
0

There are 0 answers