为什么我的 asp.net mvc 表单是 POSTing 而不是 GETting?
我的代码非常简单:
<% using(Html.BeginForm(FormMethod.Get)) %>
<% { %>
Search for in Screen Name and Email: <%: Html.TextBox("keyword", Request.QueryString["keyword"]) %>
<button type=submit>Search</button>
<% } %>
我遇到的问题是,当我提交此表单时,这些值不会添加到查询字符串中。相反,该表单似乎是通过发布请求提交的。当我查看生成的 HTML 时,我发现:
<form action="/find/AdminMember/MemberList" method="post">
Search for in Screen Name and Email: <input id="keyword" name="keyword" type="text" value="" />
<button type=submit>Search</button>
</form>
有人知道为什么吗?这对我来说似乎非常简单和直接。
My code is straightforward enough:
<% using(Html.BeginForm(FormMethod.Get)) %>
<% { %>
Search for in Screen Name and Email: <%: Html.TextBox("keyword", Request.QueryString["keyword"]) %>
<button type=submit>Search</button>
<% } %>
The issue I'm running into is that when I submit this form, the values are not added to the querystring. Instead, it appears that the form is submitting by a post request. When I look at the generated HTML, I have this:
<form action="/find/AdminMember/MemberList" method="post">
Search for in Screen Name and Email: <input id="keyword" name="keyword" type="text" value="" />
<button type=submit>Search</button>
</form>
Does anyone know why? This seems pretty simple and straighforward to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
BeginForm 帮助程序的正确签名是这样的:
当您编写
BeginForm(FormMethod.Get)
您基本上是在调用此签名 其中routeValues
参数与FormMethod.Get
无关,并且使用 POST 作为默认动词。The correct signature of the BeginForm helper is this:
When you write
BeginForm(FormMethod.Get)
you are basically invoking this signature where therouteValues
parameter has nothing to do withFormMethod.Get
and which uses POST as default verb.您将
FormMethod.Get
作为routeValues
参数传递您必须限定您的
action
和controller
来设置表单标记的FormMethod
FormExtensions.BeginForm 方法
You're passing
FormMethod.Get
as therouteValues
parameterYou will have to qualify your
action
andcontroller
to set theFormMethod
of the form tagFormExtensions.BeginForm Method
看起来好像您没有使用 BeginForm 的正确重载,请检查 此处了解各种重载。
Looks as if you are not using the correct overload for BeginForm, check here for the various overloads.