为什么Request.Url包括在里面查询字符串? [英] why Request.Url includes querystring in it?

查看:255
本文介绍了为什么Request.Url包括在里面查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的网页之一,我让用户过滤内容的基础上,他们从年龄下拉列表中选择年龄。

on one of my page, I let user to filter the content based on the age they choose from the age dropdown list.

这是我的code。

$('#age').change(function () {
         var ageUrl = "@Request.Url?age=" + $(this).val();

         alert(ageUrl);
         window.location = ageUrl;
     });

这里的问题。我的应用程序页面上。

here's the problem. I am on the app page.

HTTP://本地主机:60627 /应用

http:// localhost:60627/apps

第一次,我选择一个年龄和重定向,没有问题。

first time, I choose an age and get redirected , no problem.

HTTP://本地主机:60627 /应用年龄= Middle_School

http:// localhost:60627/apps?age=Middle_School

第二次,我挑一个又一个。

second time, I pick another one.

HTTP://本地主机:??60627 /应用年龄= Middle_School年龄= preschool

http:// localhost:60627/apps?age=Middle_School?age=Preschool

在查询字符串,年龄出现了两次。我想这两个Request.Url或Request.RawUrl,总是包含查询字符串。我应该怎么用得到的只有网页的网址查询字符串没有

in the querystring, age showed up twice. I tried both Request.Url or Request.RawUrl, always includes querystring. what should I use to get only page url without querystring.

推荐答案

我还没有真正使用过这一点,但它的工作:

I haven't really used this before but it does work:

 Request.Url.GetLeftPart(UriPartial.Path)

另一种方法是:

 String.Format("{0}://{1}{2}",Request.Url.Scheme, Request.Url.Authority, Request.Url.LocalPath)

如果您知道控制器/动作你就(从ViewContext的数据),你可以使用@ Url.Action并指定超载迫使HTTP模式这将产生一个完整的URL为好。

If you knew what controller/action you were on (from the ViewContext's data) you could use @Url.Action and specify the overload to force the http schema which would generate a full url as well.

这篇关于为什么Request.Url包括在里面查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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