简体   繁体   English

只需要在首页上的页脚中呈现表单。 Asp.net MVC

[英]Need to render form in footer only on home page. Asp.net MVC

I have a _layout.cshtml page that renders the header and footer for every page. 我有一个_layout.cshtml页面,它为每个页面呈现页眉和页脚。 In my _footer.cshtml I have a newsletter form. 在_footer.cshtml中,我有一个新闻通讯表单。 As of right now, the newsletter form is rendering on every page. 截至目前,新闻通讯表单正在每个页面上呈现。 I need it to only render on the home page footer. 我需要它仅在主页页脚上呈现。

My thought for a solution is just using an if statement that checks if we're on the home page: 我对解决方案的想法只是使用if语句来检查我们是否在主页上:

 @if(Request.RawUrl == "/")
 {
      Newsletter form
 }

My problem with this is that whenever I try to get the url, it's the same on every page. 我的问题是,每当我尝试获取url时,每个页面上的URL都是一样的。

For example: 例如:

the url might be https://something.com/checkout , so Request.RawUrl gets /checkout. 网址可能是https://something.com/checkout ,因此Request.RawUrl获取/ checkout。 But when I navigate to https://something.com , Request.RawUrl still gets /checkout. 但是当我导航到https://something.com时 ,Request.RawUrl仍然会/ checkout。 How can I get the actual path of the page? 如何获取页面的实际路径?

I've tried using just about every request.url option I can find. 我尝试使用几乎所有可以找到的request.url选项。 None of them get the actual url path of the page after being redirected to a new page. 在重定向到新页面后,它们都不获取页面的实际URL路径。 Just whatever the original one was. 不论原始版本是什么。

最好的方法是使用ViewModel而不是查询Request对象。

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

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