I have the following code in the controller:

public ActionResult method(int? id){
    var list;
    var project;
    if(id.HasValue){
       list = repository.FindAsync(Identity.User.Id);
       project = list.FirstOrDefault(p => p.Id == id);
       ViewBag.List = list;
       ViewBag.SelectedValue = project.Id;
    }
    return View();
}

And I have this in the view

<div>
  @Html.DropDownList("projectLists", ViewBag.list as List<SelectListItem>, new { @class = "class"})
</div>

How can I use the ViewBag.SelectedValue to render the dropdown with the project that have that id. I need a little help for this because I am new in ASP.NET MVC

Related posts

Recent Viewed