如何从不同的表中绑定DropDown

时间:2018-04-28 12:37:53

标签: c# sql asp.net-mvc

查看

@model IEnumerable<PinkPearl.Models.GenerateTicket_Details>

第一次下拉:

@using (Html.BeginForm("AccountDetails", "Index", FormMethod.Post, new { }))
{
     @Html.DropDownList("Value", new SelectList(ViewBag.MyCustomCollection as System.Collections.IEnumerable, "TicketNo", "TicketNo"),"Ticket No", new { @class = "collection", name = "Value", onchange = "jsFunction()" })

第二次下拉:

     @Html.DropDownList("GenerateBy", new SelectList(ViewBag.MyCustomCollection as  System.Collections.IEnumerable, "GenerateBy", "GenerateBy"),"Generate By", new { @class = "collection", name = "GenerateBy" })
}

控制器:

 List<GenerateTicket_Details> bk = new List<GenerateTicket_Details>();

 // select data from database and return in ViewBag
 ViewBag.MyCustomCollection = bk;
 return View(bk);

型号:

public class GenerateTicket_Details
{
    public List<SelectListItem> RateTable { get; set; }
    public int Id { get; set; }
    public string TicketNo { get; set; }
    public string name { get; set; }
    public string gender { get; set; }
    public string Mobile { get; set; }
    public string ArrDate { get; set; }
    public string ArrTime { get; set; }
    public string ArrDateTime { get; set; }
    public string quantity { get; set; }
    public decimal Total { get; set; }
    public decimal Refund { get; set; }
    public decimal TotalAmount { get; set; }
    public string GenerateBy { get; set; }
    public List<SelectListItem> UserMaster { get; set; }
}

我想通过使用相同的ActionResult来显示同一视图中绑定的下拉列表 Value,GenerateBy 。有人能把我送往正确的方向吗?

0 个答案:

没有答案
相关问题