简体   繁体   English

在Umbraco页面中识别Ajax请求

[英]Identify Ajax request in a Umbraco page

I use Umbraco 4.7. 我使用Umbraco 4.7。

I have a page of news - NewsPage with 3 functionalities: 我有新闻页面-具有3个功能的NewsPage

a) display the list of news (3 max on first page, module NewsList.cshtml ), a)显示新闻列表(第一页最多3个,模块NewsList.cshtml ),
b) "display detail of a news" in a popup (template Ajax\\Popup.cshtml ), and b)在弹出窗口中显示“新闻的详细信息”(模板Ajax\\Popup.cshtml ),并且
c) "display more news" (displays the next 3 news on the list). c)“显示更多新闻”(显示列表中的下3个新闻)。

As I don't know how to use 2 Ajax templates for the same page (one for popup and one for more news), 由于我不知道如何在同一页面上使用2个Ajax模板(一个用于弹出,一个用于更多新闻),
I would like to use the same module ( NewsList ) to display "next 3 news". 我想使用相同的模块( NewsList )来显示“接下来的3条新闻”。

How, in the NewsList.cshtml , to make difference between a normal "get" and an "Ajax get"? NewsList.cshtml ,如何区分普通的“ get”和“ Ajax get”?

In NewsList.cshtml, add this: 在NewsList.cshtml中,添加以下内容:

@{
var isAjax = Request.IsAjaxRequest(); 
}

Then you can use the "isAjax" variable in your Razor code to change the output. 然后,您可以在Razor代码中使用“ isAjax”变量来更改输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM