是否有Request.IsMvcAjaxRequest()相当于jQuery的? [英] Is there a Request.IsMvcAjaxRequest() equivalent for jQuery?

查看:107
本文介绍了是否有Request.IsMvcAjaxRequest()相当于jQuery的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我preFER使用jQuery和我比微软的Ajax库ASP.NET MVC应用程序。我已经加入了一个名为模式为我的行为,我在我的ajax调用设置参数。如果它被设置,我返回JsonViewResult。如果没有提供,我认为这是一个标准的HTTP POST和我返回一个ViewResult。

I prefer to use jQuery with my ASP.NET MVC apps than the Microsoft Ajax library. I have been adding a parameter called "mode" to my actions, which I set in my ajax calls. If it is provided, I return a JsonViewResult. If it isn't supplied, I assume it was a standard Http post and I return a ViewResult.

我希望能够使用jQuery,所以我可以消除我的行动额外的参数时使用类似IsMvcAjaxRequest东西在我的控制器。

I'd like to be able to use something similar to the IsMvcAjaxRequest in my controllers when using jQuery so I could eliminate the extra parameter in my Actions.

有什么在那里,将提供我的控制器内的这种能力或实现它的一些简单的方法?我不想去疯狂写作code,因为加入一个参数的作品,它只是不理想。

Is there anything out there that would provide this capability within my controllers or some simple way to accomplish it? I don't want to go crazy writing code since adding a single parameter works, it just isn't ideal.

推荐答案

下面是一个除了从M​​VC RC1发布说明 - 2009年1月

Here's an except from MVC RC1 release notes - Jan 2009

IsMvcAjaxRequest更名为IsAjaxRequest

该IsMvcAjaxRequest方法是   更名为IsAjaxRequest。作为...的一部分   这一变化,IsAjaxRequest方法   进行了更新,识别   的X请求,通过HTTP头。这是   由主要发送的公知的头   如JavaScript库   的Prototype.js,jQuery和道场。

The IsMvcAjaxRequest method been renamed to IsAjaxRequest. As part of this change, the IsAjaxRequest method was updated to recognize the X-Requested-With HTTP header. This is a well known header sent by the major JavaScript libraries such as Prototype.js, jQuery, and Dojo.

在ASP.NET AJAX佣工更新为发送这个头   要求。然而,他们继续   此外,它在形式的身体发   后期为了解决这个问题   这剥夺未知防火墙   头。

The ASP.NET AJAX helpers were updated to send this header in requests. However, they continue to also send it in the body of the form post in order to work around the issue of firewalls that strip unknown headers.

在换句话说 - 它是专门更名为更兼容与其他库

In other words - it was specifically renamed to be more 'compatible' with other libraries.

此外,任何人谁处理不当阅读完整的发布公告但一直用previous版本 - 甚至最近的β - 我强烈建议您阅读他们充分。这将节省您的时间在未来最有可能激发你的一些新功能。其相当惊人多少新的东西在里面。

In addition, for anyone who hasnt read the full release notes but has been using previous versions - even as recent as the beta - I STRONGLY recommend you read them in full. It will save you time in future and most likely excite you with some of the new features. Its quite surprising how much new stuff is in there.

重要提示::您将需要确保,如果升级从测试版RC1升级的.js文件MicrosoftAjax.MVC(没有确切的名字) - 否则这个方法是行不通的。它不是在发行说明作为必需任务中列出了升级,所以不要忘了。

Important note: You will need to make sure you upgrade the .js file for MicrosoftAjax.MVC (not the exact name) if upgrading to RC1 from the Beta - otherwise this method won't work. It isn't listed in the release notes as a required task for upgrading so don't forget to.

这篇关于是否有Request.IsMvcAjaxRequest()相当于jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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