use*_*173 6 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 name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
而且,我网站上的几个链接:
@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)
Run Code Online (Sandbox Code Playgroud)
这是`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);
}
Run Code Online (Sandbox Code Playgroud)
在第一个链接中传递了许多参数,并且都显示在浏览器的地址字段中:
这是用于第一个链接:
http://localhost:62291/LA/Film/36?activeTab=%23scheduleLink&session=15&hall=65&client=2&count=1
Run Code Online (Sandbox Code Playgroud)
这是第二个链接:
http://localhost:62291/LA/Film/36?activeTab=%23scheduleLink
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
http://localhost:62291/LA/Film/36
Run Code Online (Sandbox Code Playgroud)
在地址行中隐藏参数的方法有哪些?
更新:
$(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);
}
Run Code Online (Sandbox Code Playgroud)
调用了所有操作,但未EventInfo加载我的 视图。
您可以使用 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>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21158 次 |
| 最近记录: |