Using DropDown List
First, we want to convert our Activity section to be a dropdown list instead of text input. The idea is set the entries that we already have in Data class inside Data folder to ViewBag and call the ViewBag in Add page.
Inside Add action (not after Post page), we could add the ViewBag that we wanted.
ViewBag.SelectListItem = new SelectList(Data.Data.Activities, "Id", "Name");
The code above shows the select List properties by input from Data.Data.Activities. Due to every activity has attributes "Id" and "name", we need to specify them too.
That's all. Now, we call the ViewBag in our View page.
<div class="form-group">
@Html.LabelFor(m => m.ActivityId, new { @class = "control-label" })
@Html.TextBoxFor(m => m.ActivityId, new { @class = "form-control" })
</div>
Just change the TextBoxFor to DropDownListFor, but with different parameters thrown.
<div class="form-group">
@Html.LabelFor(m => m.ActivityId, new { @class = "control-label" })
@Html.DropDownListFor(m => m.ActivityId, (SelectList)ViewBag.SelectListItem, "Pick an Item",
new { @class = "form-control" })
</div>
Then we s