hide parameters passing to controller in address b

2019-01-28 07:48发布

问题:

I have the following routes:

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

And, several links on my site:

@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)

This is `EventOverview action:

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

In the first link passing many parameters, and all shows in browser's address field:
This is for firts link:

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

This is for second link:

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

I want something like that:

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

What ways to hide parameters in an address line are?

UPDATE:

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

All actions are called, but my EventInfo view not loaded.

回答1:

You could use POST instead of GET. So you could replace the link with a form containing hidden fields for the parameters that you don't want to appear in the query string:

@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>
}


回答2:

How to hide URL Parameters

If you want to hide URL parameters, you go to debug properties and you select the radiobutton option and specify thatc specificpage:

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

This is the parameter URL. If you want to hide like this:

http://localhost:61757/Controller/index

You have to put in a specific page as when you open the page, it will not display URL parameters.