Select-Tag Helper .NET Core 到控制器

我尝试使用“提交”按钮提交标签选择并且它工作正常但是没有提交按钮怎么样?


我想每次在没有 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

}


元芳怎么了
浏览 114回答 1
1回答

浮云间

尝试这个:<select&nbsp;asp-for="EmployeeId"&nbsp;asp-items="@(new&nbsp;SelectList(Model.EmployeesList,"Id","FullName"))"&nbsp;onchange="this.form.submit()"> &nbsp;&nbsp;&nbsp;&nbsp;...</select>
打开App,查看更多内容
随时随地看视频慕课网APP