MVC ViewBag传值
1.单值
cs
public ActionResult Authority() { int targetId = int.Parse(Request.QueryString["id"]);//接收id ViewBag.targetId = targetId; return View(); }
cshtml
<input id="UserID" name="UserID" value="@ViewBag.targetId" type="hidden" />
2.list
cs
public ActionResult Index() { DDLCompany ddlCompany=new DDLCompany(); IEnumerable<SelectListItem> companyList = ddlCompany.BuildCompanyDDL(); ViewBag.companyList = companyList; return View(); }
cshtml
<div class="fitem"> <label>公司: </label> <select class="easyui-combobox" id="company" style="width: 150px" name="company"> @foreach (SelectListItem com in ViewBag.companyList as IEnumerable<SelectListItem>) { <option value="@com.Value">@com.Text</option> } </select></div>