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>公司:&nbsp</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>

 

posted @ 2015-12-21 14:09  时代码农  阅读(1840)  评论(0编辑  收藏  举报