Select-Tag Helper .NET Core to Controller

亡梦爱人 提交于 2019-12-25 01:27:30

问题


I have tried to submit tag-select with 'submit' button and it worked properly but how about without submit button ?

I want to send the value of tag-select directly to controller every time it changes without javascript. Is that possible ?

@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:


Try this:

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


来源:https://stackoverflow.com/questions/54217867/select-tag-helper-net-core-to-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!