在ASP.Net MVC脚手架层叠的DropDownList [英] Cascading dropdownlist in ASP.Net MVC Scaffolding

查看:126
本文介绍了在ASP.Net MVC脚手架层叠的DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用级联的DropDownList在ASP.Net MVC脚手架?如果是的话,怎么样?

Is it possible to use cascading dropdownlist in ASP.Net MVC scaffolding? If yes, how?

我这里有一些codeS中,将显示在使用脚手架的DropDownList:

I have here some of the codes that will show the dropdownlist using scaffolding:

MyController.cs

// GET:/ ManualEntries /创建

// GET: /ManualEntries/Create

    public ActionResult Create()
    {
        ViewBag.cluscd = new SelectList(db.CLUSTERs, "clus_id", "clusdesc");
        ViewBag.seccd = new SelectList(db.SECTORs, "sec_id", "secdesc");
        return View();
    }

Create.cshtml

    <div class="form-group">
        @Html.LabelFor(model => model.sec_id, "Sector", new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("sec_id", String.Empty)
            @Html.ValidationMessageFor(model => model.sec_id)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.clus_id, "Cluster", new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("clus_id", String.Empty)
            @Html.ValidationMessageFor(model => model.clus_id)
        </div>
    </div>

希望你能帮助我的人!感谢:)

Hope you can help me guys! Thanks :)

推荐答案

您可以像这样

控制器

List<SelectListItem> selectlist = new List<SelectListItem>();
//fill the list and assign to viewbag and than access in view
ViewBag.SelectList = selectlist;

查看

@Html.DropDownList("name",(IEnumerable<SelectListItem>)ViewBag.SelectList)

这篇关于在ASP.Net MVC脚手架层叠的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆