码迷,mamicode.com
首页 > Web开发 > 详细

MVC ViewBag传值

时间:2015-12-21 15:46:36      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

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>

 

MVC ViewBag传值

标签:

原文地址:http://www.cnblogs.com/JarvisNote/p/5063268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!