@ html.DropdownListFor选择的值不会更新

时间:2017-08-29 09:55:25

标签: asp.net-mvc razor asp.net-mvc-5

我是ASP.NET MVC5的新手,我想要执行的是非常基本的,但我无法理解如何做到这一点。我尝试将一个选项从下拉列表发送到另一个页面但没有成功。这是我的代码:

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)

无论我做什么,&#34;选择&#34;永远等于0.请有人帮帮我吗?

0 个答案:

没有答案