I hope this will work for you as you are trying to keep selected value in a ViewBag.
public class UserVM
{
public string Year { set; get; }
public string Month { set; get; }
public string Day{ set; get; }
}
Set value in a viewbag and bind
[HttpGet]
public ActionResult Register(User user)
{
ViewBag.Year = new SelectList(
new List<SelectListItem>
{
new SelectListItem { Text = "1368", Value = "1987" },
new SelectListItem { Text = "1369", Value = "1988"},
}, "Value" , "Text");
return View();
}
@using (Html.BeginForm())
{
<div class="form-group">
@Html.DropDownListFor(m => m.Year, (SelectList)ViewBag.Year, "Select one")
</div>
<button type="Submit" class="btn btn-success submit">Send</button>
}
Get the selected value and set it into another view bag.
[HttpPost]
public ActionResult Register(VM model)
{
if(!ModelState.IsValid)
{
ViewBag.SelectedYear = model.Year;
}
return View();
}