Ajax.BeginForm 指定“GET"类型发布 [英] Ajax.BeginForm to specify "GET" type posting

查看:24
本文介绍了Ajax.BeginForm 指定“GET"类型发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的观点如下:

<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.

我什至在浏览器中通过 view-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-unobtrusive)实际上就在那里)

(Notice that the script (jquery-unobstrusive) actually is there)

推荐答案

但是,在我的 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.

jquery.unobtrusive-ajax.js 脚本忽略 method 属性并使用 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.

这篇关于Ajax.BeginForm 指定“GET"类型发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆