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

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

问题描述

我的观点如下:

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

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

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