Как установить DropdownList выбранный элемент на странице редактирования ?.Какой код я должен написать в DropdownList вместо «Ничего» * 1001 *
![ِDebuge mode - picture 1](https://i.stack.imgur.com/i3R74.png)
![Debuge mode - picture 2](https://i.stack.imgur.com/OjuNB.png)
![List View that showing 1 Row - picture 3](https://i.stack.imgur.com/ujLJn.png)
![Edit view page with DDL - picture 4](https://i.stack.imgur.com/d0auX.png)
Это контроллер:
' GET: MachinInfo/Edit/5
Function MachinInfoEdit(ByVal id As Integer?) As ActionResult
If IsNothing(id) Then
Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
End If
Dim machinInfo As MachinInfo = db.MachinInfo.Find(id)
If IsNothing(machinInfo) Then
Return HttpNotFound()
End If
ViewBag.BrandID = New SelectList(db.Brand, "Id", "BrandName")
Return View(machinInfo)
End Function
' POST: MachinInfo/Edit/5
<HttpPost()>
<ValidateAntiForgeryToken()>
Function MachinInfoEdit(<Bind(Include:="Id,PelakStateID,MachinStateID,OrgCode,MachineID,BrandID,MachintypeID,NPlate,NPlateL,NPlateM,NPlateR,CardSerial,VIN,Myear,Color,GearTypeID,MCost,Mcamp,Description,LogI,LogE")> ByVal machinInfo As MachinInfo) As ActionResult
If ModelState.IsValid Then
db.Entry(machinInfo).State = EntityState.Modified
db.SaveChanges()
Return RedirectToAction("Index")
End If
ViewBag.BrandID = New SelectList(db.Brand, "Id", "BrandName")
Return View(machinInfo)
End Function
и мой вид редактирования:
<div class="form-group col-md-6">
@Html.LabelFor(Function(model) model.BrandID, htmlAttributes:=New With {.class = "control-label col-md-2"})
<div class="col-md-10">
@Html.DropDownList("BrandID", Nothing, "-select-", htmlAttributes:=New With {.class = "form-control"})
@Html.ValidationMessageFor(Function(model) model.BrandID, "", New With {.class = "text-danger"})
</div>
</div>