I'm new to ASP.NET MVC5 and what I want to perform is pretty basic, but I just can't wrap my head around how to do that. I try to send a selection from a dropdownlist to another page with no success. Here is my code :
ViewModel.cs
namespace Models
{
public class SQViewModel
{
public List<SelectListItem> listVersions { get; set; }
public int currentSelectedVersionId { get; set;}
public SQViewModel(){
listVersions = new List<SelectListItem>()
{
new SelectListItem(){ Value="0", Text="VersionA"},
new SelectListItem(){ Value="1", Text="VersionB"},
new SelectListItem(){ Value="2", Text="VersionC"},
new SelectListItem(){ Value="3", Text="VersionD"},
new SelectListItem(){ Value="4", Text="VersionE"}
};
}
}
}
HomeController.cs
public class HomeController : Controller
{
public ActionResult Index()
{
var Model = new SQViewModel();
return View(Model);
}
public ActionResult Build(int Selected)
{
return View();
}
}
Index.cshtml
@model Models.SQViewModel
@Html.DropDownListFor(m => m.currentSelectedVersionId, Model.listVersions)
@Html.ActionLink("Build", "Build", "Home", new { Selected = Model.CurrentSelectedVersionId },null)
Whatever I do, "Selected" always equals 0. Could someone help me with this, please?