我正在尝试让 MVC 生成正确的 url。
现在结果是这样的: http ://domain.com/Live/Schedule?date=2013-03-29
它当然应该像这样正确地生成它:http: //domain.com/Live/Schedule/2013-03-29
我的全球.Asax
routes.MapRoute(
name: "LiveSchedule", // Route name
url: "Live/{action}/{date}", // URL with parameters
defaults: new { controller = "Live", action = "Schedule", date = UrlParameter.Optional }
);
网页上触发请求的代码:
@using(Html.BeginForm("Schedule", "Live", FormMethod.Get))
{
<div>
Specify a date: @Html.DropDownList("date", Model.SelectedDateList) <input type="submit" value="Display"/>
</div>
}
结果:
<form action="/Live/Schedule" method="get">
<div>
Select a date: <select id="date" name="date"><option value="2013-03-27">27 onsdag</option>
<option value="2013-03-28">28 torsdag</option>
<option selected="selected" value="2013-03-29">29 fredag</option>
<option value="2013-03-30">30 lördag</option>
<option value="2013-03-31">31 söndag</option>
...
</select> <input type="submit" value="Display"/>
</div>
</form>
接受输入的控制器:
public ActionResult Schedule(string date)
{
var model = getModel(date);
return View(model);
}
我究竟做错了什么?