I am trying to submit when a dropdownlist changes by doing this
@using (Html.BeginForm("testAction", "FishingTrip"))
{
@Html.DropDownListFor(x => x.Day, Model.Days, new { onchange="this.form.submit();" })
}
This works fine but I am having problems (in other words don't know how) to get the option value on the server, can anybody help me with this ?
cheers sushiBite
You could simply have your POST controller action take it as parameter and leave the default model binder to the binding:
[HttpPost]
public ActionResult TestAction(string day)
{
// The day parameter will contain the selected value
...
}
Or directly use the view model you used in the view:
[HttpPost]
public ActionResult TestAction(MyViewModel model)
{
// The model.Day parameter will contain the selected value
...
}
就像其他任何属性/编辑器一样,只需使用model参数的Day
属性。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.