部分视图在POSTBACK上返回NULL

我的局部视图在提交表单时返回Null 主视图不为null,它包含表单提交中的值,我正在使用渲染局部视图来包含局部视图。也将模型传递给局部视图,也尝试将模型传递给局部视图动作结果,但结果相同。任何帮助将不胜感激 谢谢

查看

  ```  <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,@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> ```

模型类

```  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; }
    } ```

操作方法

 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();
        } 
lgxiaoshu 回答:部分视图在POSTBACK上返回NULL

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1398519.html

大家都在问