繁体   English   中英

Razor @ Html.DropDownListFor提交并在服务器上获取选项值

[英]Razor @Html.DropDownListFor submit & get the option value on the server

我正在尝试通过下拉列表更改提交

@using (Html.BeginForm("testAction", "FishingTrip"))
{
    @Html.DropDownListFor(x => x.Day, Model.Days,  new { onchange="this.form.submit();" })
}

这可以正常工作,但是我在获取服务器上的选项值时遇到问题(换句话说,不知道如何操作),有人可以帮助我吗?

干杯寿司

您可以简单地让POST控制器操作将其作为参数,并将默认的模型绑定器保留在绑定中:

[HttpPost]
public ActionResult TestAction(string day)
{
    // The day parameter will contain the selected value
    ...
}

或直接使用您在视图中使用的视图模型:

[HttpPost]
public ActionResult TestAction(MyViewModel model)
{
    // The model.Day parameter will contain the selected value
    ...
}

就像其他任何属性/编辑器一样,只需使用model参数的Day属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM