问题描述
我的观点如下:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
@using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "Get", InsertionMode = InsertionMode.Replace, UpdateTargetId = "DisplayPatients" }))
{
<input type="search" name="searchTerm" />
<input type="submit" value="Do Search" />
}
每当我尝试编译并查看html页面的来源时,我得到,我明白了,
Whenever I try to compile and I view the source of the html page that I get, I see,
<form action="/" data-ajax="true" data-ajax-method="Get" data-ajax-mode="replace" data-ajax-update="#DisplayPatients" id="form0"
method="post">
但是,在我的Ajax.BeginForm中,我指定 HttpMethod = Get
。尽管如此,我在输出html页面中得到 method =post
。
But, in my Ajax.BeginForm, I specify the HttpMethod = Get
. Inspite being this, I get the method = "post"
in the output html page.
任何想法为什么?提前致谢。
Any ideas why ? Thanks in advance.
编辑:
我甚至通过查看我的页面来源-source
在我的浏览器中。这显示:
I even checked my page source by view-source
in my browser. This shows:
<script src="/Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>
<form action="/" data-ajax="true" data-ajax-method="Get" data-ajax-mode="replace" data-ajax-update="#DisplayPatients" id="form0" method="post"> <input type="search" name="searchTerm" />
(注意脚本(jquery-unobstrusive)实际上就在那里)
(Notice that the script (jquery-unobstrusive) actually is there)
推荐答案
但是,在我的Ajax.BeginForm中,我指定了HttpMethod = Get。尽管这是,但我在输出html页面中得到方法=post。
But, in my Ajax.BeginForm, I specify the HttpMethod = Get. Inspite being this, I get the method = "post" in the output html page.
jquery.unobtrusive-ajax.js
脚本忽略方法
属性并使用 data-ajax-method
(如果有的话)。所以实际的请求将是GET。查看您的Google Chrome开发者控制台的网络标签,查看。
The jquery.unobtrusive-ajax.js
script ignores the method
attribute and uses data-ajax-method
(if present). So the actual request will be GET. Look at the Network tab of your Google Chrome developer console to see.