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.
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. 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">×</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">×</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; }
}
答案 0 :(得分:0)
我得到了这个问题的解决方案。现在它正在使用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();
}