选择标记助手.NET Core到控制器

时间:2019-01-16 13:15:05

标签: c# asp.net-core tag-helpers

我尝试使用“提交”按钮提交标记选择,它正常工作,但是没有提交按钮怎么办?

我希望每次更改时都将tag-select的值直接发送到控制器,而无需使用javascript。有可能吗?

@model MyViewModel
<form asp-controller="Home" asp-action="Create">
    <select asp-for="EmployeeId" asp-items="@(new SelectList(Model.EmployeesList,"Id","FullName"))">
        <option>Please select one</option>
    </select>
</form>


[HttpPost]
public IActionResult Create(MyViewModel model)
{
    //check model.EmployeeId 
    //to do : Save and redirect
}

1 个答案:

答案 0 :(得分:1)

尝试一下:

<select asp-for="EmployeeId" asp-items="@(new SelectList(Model.EmployeesList,"Id","FullName"))" onchange="this.form.submit()">
    ...
</select>