lundi 29 juin 2015

Dropdownlist in MVC with Where cluase in entities

I am new to MVC. I want to fill Dropdownlist only where Account_Type = "D". Here is my Edit.cshtml

<div class="form-group">
        @Html.LabelFor(model => model.Account_Code, "Account_Code", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("Account_Code", null, htmlAttributes: new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.Account_Code, "", new { @class = "text-danger" })
        </div>
    </div>

And here is my Edit Controller

public ActionResult Edit(int? id)
{
    ViewBag.Account_Code = new SelectList(db.Chart_Of_Account, "Account_Code", "Account_Desc", student.Account_Code);
}

Aucun commentaire:

Enregistrer un commentaire