Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在地址栏中隐藏传递给控制器的参数(URL重写或其他)_Asp.net Mvc_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 在地址栏中隐藏传递给控制器的参数(URL重写或其他)

Asp.net mvc 在地址栏中隐藏传递给控制器的参数(URL重写或其他),asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,我有以下路线: routes.MapRoute("Event Overview", "{city}/{type}/{id}", new {city="LA", controller = "BaseEvent", action = "EventOverview"}, new {city = new CityConstraint()}); routes.MapRoute( "Default", // Route

我有以下路线:

routes.MapRoute("Event Overview", "{city}/{type}/{id}",
                            new {city="LA", controller = "BaseEvent", action = "EventOverview"}, new {city = new CityConstraint()});

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
还有,我网站上的几个链接:

@Html.ActionLink("Make", "EventOverview", "BaseEvent", new { id = eventInfo.Key.OID, type = eventInfo.Key.XPObjectType.TypeName.GetShortTypeName(), activeTab = "#scheduleLink", session = eventInfo.Key.EventSchedules[0].SessionId, hall = eventInfo.Key.EventSchedules[0].HallId, client = eventInfo.Key.EventSchedules[0].BasePlace.PremieraClientId}, null)

@Html.ActionLink("Make", "EventOverview", "BaseEvent", new { id = eventInfo.Key.OID, type = eventInfo.Key.XPObjectType.TypeName.GetShortTypeName(), activeTab = "#scheduleLink",  }, null)
这是“事件概述”操作:

 public ActionResult EventOverview(int id, string type, string activeTab,string hall, string session, string client, string count)
        {
            var model = CreateEventViewData<EventViewData>(id, type);
            model.ActiveTab = activeTab;
            model.ScheduleCount = count;
            model.SessionId = session;
            model.HallId = hall;
            model.ClientId = client;
            return View("Controls/EventsInfo/EventInfo", model);
        }
这是第二个链接:

http://localhost:62291/LA/Film/36?activeTab=%23scheduleLink
我想要这样的东西:

http://localhost:62291/LA/Film/36
在地址行中隐藏参数的方法有哪些

更新:


调用了所有操作,但未加载“我的事件信息”视图。

您可以使用POST而不是GET。因此,您可以将链接替换为一个表单,该表单包含不希望出现在查询字符串中的参数的隐藏字段:

@using (Html.BeginForm("EventOverview", "BaseEvent", new { id = eventInfo.Key.OID, type = eventInfo.Key.XPObjectType.TypeName.GetShortTypeName() }, FormMethod.Post, null))
{
    @Html.Hidden("activeTab", "#scheduleLink")
    @Html.Hidden("session", eventInfo.Key.EventSchedules[0].SessionId)
    @Html.Hidden("hall", eventInfo.Key.EventSchedules[0].HallId)
    @Html.Hidden("client", eventInfo.Key.EventSchedules[0].BasePlace.PremieraClientId)
    <button type="submit">Make</button>
}
如何隐藏URL参数

如果要隐藏URL参数,请转到“调试属性”,选择radiobutton选项并指定thatc 具体页面:

http://localhost:61757/TicketDataUpload/templateupload?projectid=6497&userid=7336
这是参数URL。如果要像这样隐藏:

http://localhost:61757/Controller/index

你必须放入一个特定的页面,因为当你打开页面时,它不会显示URL参数。

我有点难看的解决方案:将代码保持原样,然后在加载html文档后,服务器已经使用了你的查询字符串数据,在javascript中使用如下方式更改地址栏中的URL:

$(document).ready(function () {
    let hrefWithoutQueryString = window.location.href.split('?')[0];
    // args below are 'state' (irrelevant for me), 'title' (so far, 
    // ignored by most browsers) and 'url' (will appear in address bar)
    history.pushState({ }, '', hrefWithoutQueryString);
});
在一瞬间,查询字符串将出现在地址栏中,但在上面的js运行之后,url中包括“?”和“?”之后的所有内容都将消失

显然,一个副作用是它会改变浏览器的会话历史记录,但这对我来说不是问题


请注意,我已将空状态再次传递到pushState,这对我来说不是问题,但可能会导致问题,具体取决于应用程序的路由设置以及它是否使用状态变量。

如果需要参数中的值,则不能“隐藏”它们,你必须设法让他们回到服务器上。您可以将它们发布到服务器,也可以将它们发送到URL中,执行所做的操作,然后重定向到控制器/操作,而不指定其中的大部分,将所需的数据存储在TempData或Session中。当您需要来自客户端的数据时,此处没有太多选项。@Tommy:我为此链接编写了一个处理程序,并执行以下操作:在我称为RedirectToAction的操作中,防止默认值和执行post请求。请参阅更新问题。我们如何在web窗体中执行此操作,我在web窗体中使用路由概念,并希望隐藏参数
http://localhost:61757/Controller/index
$(document).ready(function () {
    let hrefWithoutQueryString = window.location.href.split('?')[0];
    // args below are 'state' (irrelevant for me), 'title' (so far, 
    // ignored by most browsers) and 'url' (will appear in address bar)
    history.pushState({ }, '', hrefWithoutQueryString);
});