隐藏参数传递给控制器​​在地址栏(URL重写或别的东西)(hide parameters passi

2019-06-23 18:01发布

我有以下途径:

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)

这是`EventOverview行动:

 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);
        }

在第一个环节传递很多参数,所有节目在浏览器的地址栏:
这是firts链接:

http://localhost:62291/LA/Film/36?activeTab=%23scheduleLink&session=15&hall=65&client=2&count=1

这是第二个环节:

http://localhost:62291/LA/Film/36?activeTab=%23scheduleLink

我想这样的事情:

http://localhost:62291/LA/Film/36

有什么方法可以隐藏参数的地址线是谁?

更新:

$(document).ready(function () {
        var link = $(".btn_buy_ticket").find("a").click(function (e) {
            e.preventDefault();            
            $.post($(this).attr("href"));
        });
    })

[HttpPost]
        public ActionResult EventOverview(int id) // just for test
        {
            return RedirectToAction("EventOverview", new {id = id});
        }

        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);
        }

所有操作调用,但我EventInfo视图中未加载。

Answer 1:

你可以使用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>
}


Answer 2:

如何隐藏URL参数

如果你想隐藏的URL参数,你去调试性能和您所选择的radiobutton选项,并指定thatc specificpage:

http://localhost:61757/TicketDataUpload/templateupload?projectid=6497&userid=7336

这是参数的URL。 如果要隐藏这样的:

http://localhost:61757/Controller/index

你必须把在一个特定的页面,当你打开页面,则不会显示URL参数。



文章来源: hide parameters passing to controller in address bar (URL rewrite or something else)