【问题标题】:I am new to MVC 5, I want to bind dropdownlistfor from master table and entityframework6我是 MVC 5 的新手,我想从主表和 entityframework6 绑定 dropdownlistfor
【发布时间】:2018-07-23 16:22:09
【问题描述】:

我是 MVC 5 的新手,我想从主表和 entityframework6 绑定 dropdownlistfor。我正在创建建筑页面,在该页面上我想绑定建筑所在的分支列表。 要获取数据,我使用的是 EntityFramework 6。

【问题讨论】:

标签: entity-framework asp.net-mvc-5


【解决方案1】:

在控制器页面中:

private DBEntities db = new DBEntities();

    public ActionResult Load()
    {
        ViewBag.PlusOrMinus1 = new SelectList(db.t_CartesianSymbol, "CartId", "CartesianSymbol");
        return View();
    }

在查看页面中:

<div class="row poc-row-alert">
        <div class="col-md-3">
            @Html.LabelFor(model => model.PlusOrMinus1, "Operator 1", htmlAttributes: new { @class = "control-label" })
        </div>
        <div class="col-md-9">
            @Html.DropDownList("PlusOrMinus1", null, htmlAttributes: new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.PlusOrMinus1, "", new { @class = "text-danger" })
        </div>
    </div>

请进行必要的更改。

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 2019-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多