简体   繁体   English

每个组提交单选按钮

[英]Submit Radio button from each group

I have a view as following Image. 我有以下图像的观点。

单选按钮组 For this I have a table TimeType for the Time type(eg: Breakfast, Lunch, Dinner), another table DishType for Dish type(eg: Main Dish, Side Dish, Desert etc), and an Table for the Item .Following radio buttons are using to select one of the Item from each Dish type. 为此,我有一个用于时间类型的表TimeType (例如:早餐,午餐,晚餐),另一个用于DishType类型的表DishType (例如:主菜,配菜,沙漠等),以及用于Item的表。用来从每种菜式中选择一项。 For an example, I can choose a dish from Breakfast-Main dish, Breakfast-Sub dish and a Breakfast-Desert and same from Lunch and Dinner.The radio button and Get working perfectly. 举一个例子,我可以选择从早餐,主菜,早餐子菜和早餐,沙漠和同样从午餐和晚上营业,单选按钮盘中, Get完美的工作。 I want to submit these entire radio button which are choosed. 我要提交所有选中的整个单选按钮。 Now the problem is I want to submit the entire radio button which are choosed from each category. 现在的问题是我要提交从每个类别中选择的整个单选按钮。

View

@{
    Layout = null;
 }
@model GreenApple.CustSingleMenu
@if (Model.FoodGroupName != null)
{
    using (Html.BeginForm("CustomerMenu", "Customer", FormMethod.Post))
    {
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">

                    <h5 class="modal-title" id="exampleModalLabel">@Model.FoodGroupName</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>

                <div class="modal-body">
                    <div class="row">
                        @foreach (var item1 in Model.timetypedisplay)
                        {
                            <div class="col-12 col-sm-4 col-md-4 collg-4 col-xl-4">
                                <div class="box-wrapper2">
                                    <h3 class="title1">@item1.TimeTypeName</h3>
                                    @foreach (var item2 in item1.dishtypedisplay)
                                    {

                                        <div>
                                            <h5 class="sub_title">@item2.DishTypeName</h5>
                                            @foreach (var item3 in item2.itemlistdisplay)
                                            {

                                                <div class="menu_list_row clearfix">
                                                    <div class="checkbox_wrapper">
                                                        <input class="checkbox_style" type="radio" id="cb1_@item3.ItemID" name="cb_@item3.Group1Id">
                                                        <label for="cb1_@item3.ItemID"></label>
                                                    </div>
                                                    <div class="menu_list">
                                                        <h6>@item3.ItemName</h6>
                                                        <div class="greenColor sub_des">
                                                            @item3.ItemCalorie
                                                        </div>
                                                    </div>
                                                </div>
                                            }
                                        </div>
                                    }
                                </div>
                            </div>
                        }
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn_default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btnStyle3">Save changes</button>
                </div>
            </div>
        </div>
    }
}
else
{

    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">

                <h5 class="modal-title" id="exampleModalLabel">Admin Update Pending</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body">
                <center>Updated Soon</center>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn_default" data-dismiss="modal">Close</button>
                <button type="button" class="btnStyle3">Save changes</button>
            </div>
        </div>
    </div>
} 

Update in question

ViewModel

 public class CustSingleMenu
{
    public long FoodGroupId { get; set; }
    public string FoodGroupName { get; set; }
    public DateTime Date { get; set; }
    public List<TimeTypeDisplay> timetypedisplay { get; set; }
}
public class TimeTypeDisplay
{
    public long Id { get; set; }
    public long TimeTypeId { get; set; }
    public long FoodGroupId { get; set; }
    public string TimeTypeName { get; set; }
    public List<DishTypeDisplay> dishtypedisplay { get; set; }

}
public class DishTypeDisplay
{
    public long DishTypeId { get; set; }
    public long Grp1Id { get; set; }
    public string DishTypeName { get; set; }
    public List<ItemListDisplay> itemlistdisplay { get; set; }
}
public class ItemListDisplay
{
    public long ItemID { get; set; }
    public long Grp2Id { get; set; }
    public string ItemName { get; set; }
    public string ItemNameAr { get; set; }
    public string ItemCalorie { get; set; }
    public long Group1Id { get; set; }
    public bool Status { get; set; }
}

I got the solution for this issue. 我已经找到了解决这个问题的方法。 Now it is working with FormCollection 现在它正在使用FormCollection

 [HttpPost]
    public ActionResult CustomerMenu(FormCollection Fq)
    {
        string mail = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name.Split('|')[0];
        var usr = _customer.GetUserByEmail(mail);
        List<CustomerMenu> custmenulist = new List<Models.CustomerMenu>();
        foreach (var key in Fq.Keys)
        {
            if(Fq["Date"]!= Fq[key.ToString()])
            {
                var dd = Fq["Date"];
                var value = Fq[key.ToString()];
                CustomerMenu custmenu = new Models.CustomerMenu();
                custmenu.CustMenu_ItemID = Convert.ToInt64(value);
                custmenu.CustMenu_CustID = usr.CustID;
                custmenu.CustMenuDate =Convert.ToDateTime(dd);
                custmenu.CustMenu_EnteredOn = DateTime.Now;
                _customermenu.Add(custmenu);
            }
        }
        return View();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM