0

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?

adiga
  • 34,372
  • 9
  • 61
  • 83
  • 1
    Because the initial value of `CurrentSelectedVersionId` is `0`. `@Html.ActionLink()` is razor code (its parsed on the server before its sent to the client). Selecting an option does not magically update the `href` attribute of your link - you need javascriptt for that –  Aug 29 '17 at 09:58
  • Thanks a lot for the clarification. – S. Fourreau Aug 29 '17 at 12:51

0 Answers0