〜/查看/ _TopNavigation.cshtml:
<form method="POST" action="/">
@Html.AntiForgeryToken()
@Html.DropDownList("SelectionId", null, htmlAttributes: new { @class = "form-control", onchange = "this.form.submit();" })
</form>
〜/控制器/ BaseController.cs
protected override void Initialize(RequestContext requestContext)
{
base.Initialize(requestContext);
// SelectionIdlogic here
}
在处理新的SelectionId值时,我希望将页面路由到当前控制器/操作,而不是发布到&#34; /&#34 ;.
答案 0 :(得分:-1)
使用:
@using (Html.BeginForm())
{}
这会将表单发布到与当前视图的POST
操作相对应的操作。
答案 1 :(得分:-1)
using (Html.BeginForm("Action", "Controller", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.DropDownList("SelectionId", null, htmlAttributes: new { @class = "form-control", onchange = "this.form.submit();" })
}