这是我一直在尝试的:
@Html.DropDownList("DropDownValue", new SelectList(ViewBag.sellectedSubjects, "text"), "select one", new { onchange = "this.form.action='/Profile/Edit';this.form.submit();" })
这可行,但它调用 POST 而不是我想要的 Edit GET。我怎样才能做到这一点?
这是我一直在尝试的:
@Html.DropDownList("DropDownValue", new SelectList(ViewBag.sellectedSubjects, "text"), "select one", new { onchange = "this.form.action='/Profile/Edit';this.form.submit();" })
这可行,但它调用 POST 而不是我想要的 Edit GET。我怎样才能做到这一点?
只要你改变了动作,为什么不也改变方法呢?
new { onchange = "this.form.method='GET';this.form.action='/Profile/Edit';this.form.submit();" })
或者在 Razor/HTML 中更改它(我会说这是更可取的,因为从一开始就使 HTML 正确而不是用 Javascript 破解它通常更干净):
@using (Html.BeginForm("Action", "Controller", FormMethod.Get))
{
// ...
}