隐藏参数传递给控制器​​在地址栏(URL重写或别的什么) [英] hide parameters passing to controller in address bar (URL rewrite or something else)

查看:116
本文介绍了隐藏参数传递给控制器​​在地址栏(URL重写或别的什么)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下途径:

  routes.MapRoute(事件概述,{城市} / {类型} / {ID}
                            新{城市=LA,控制器=BaseEvent,行动=EventOverview},{新都市=新CityConstraint()});routes.MapRoute(
                默认,//路线名称
                {控制器} / {行动} / {ID},// URL带参数
                新{控制器=家,行动=索引,ID = UrlParameter.Optional} //参数默认
            );

和,在我的网站的几个环节:

  @ Html.ActionLink(使,EventOverview,BaseEvent,新{ID = eventInfo.Key.OID,键入= eventInfo.Key.XPObjectType.TypeName.GetShortTypeName (),activeTab =#scheduleLink,会话= eventInfo.Key.EventSchedules [0] .SessionId,大厅= eventInfo.Key.EventSchedules [0] .HallId,客户端= eventInfo.Key.EventSchedules [0] .BasePlace。premieraClientId},NULL)@ Html.ActionLink(使,EventOverview,BaseEvent,新{ID = eventInfo.Key.OID,键入= eventInfo.Key.XPObjectType.TypeName.GetShortTypeName(),activeTab =#scheduleLink},空值)

这是`EventOverview动作:

 公众的ActionResult EventOverview(INT ID,字符串类型,字符串activeTab,串堂,串会话,客户端串,串计数)
        {
            VAR模型= CreateEventViewData< EventViewData>(ID,类型);
            model.ActiveTab = activeTab;
            model.ScheduleCount =计数;
            model.SessionId =会议;
            model.HallId =大厅;
            model.ClientId =客户端;
            返回视图(控制/ EventsInfo / EventInfo模型);
        }

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

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

这是第二个链接:

 的http://本地主机:62291 / LA /电影/ 36 activeTab =%23scheduleLink

我想是这样的:

 的http://本地主机:62291 / LA /电影/ 36

什么方法可以隐藏在地址行参数?

更新:

  $(文件)。就绪(函数(){
        VAR链接= $(。btn_buy_ticket)。找到(A)。点击(函数(五){
            亦即preventDefault();
            $。员额($(本).attr(HREF));
        });
    })[HttpPost]
        公众的ActionResult EventOverview(INT ID)//只是为了测试
        {
            返回RedirectToAction(EventOverview,新{ID = ID});
        }        公众的ActionResult EventOverview(INT ID,字符串类型,字符串activeTab,串堂,串会话,客户端串,串计数)
        {
            VAR模型= CreateEventViewData&LT; EventViewData&GT;(ID,类型);
            model.ActiveTab = activeTab;
            model.ScheduleCount =计数;
            model.SessionId =会议;
            model.HallId =大厅;
            model.ClientId =客户端;
            返回视图(控制/ EventsInfo / EventInfo模型);
        }

所有操作调用,但并没有载入我的 EventInfo 视图。


解决方案

您可以使用POST而不是GET。所以,你可以替换包含隐藏字段,你不希望出现在查询字符串参数形式的链接:

  @using(Html.BeginForm(EventOverview,BaseEvent,新{ID = eventInfo.Key.OID,键入= eventInfo.Key.XPObjectType.TypeName.GetShortTypeName() },FormMethod.Post,NULL))
{
    @ Html.Hidden(activeTab,#scheduleLink)
    @ Html.Hidden(会话,eventInfo.Key.EventSchedules [0] .SessionId)
    @ Html.Hidden(堂,eventInfo.Key.EventSchedules [0] .HallId)
    @ Html.Hidden(客户,eventInfo.Key.EventSchedules [0] .BasePlace。premieraClientId)
    &LT;按钮式=提交&GT;使&LT; /按钮&GT;
}

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.

解决方案

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

这篇关于隐藏参数传递给控制器​​在地址栏(URL重写或别的什么)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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