我正在尝试让MVC生成正确的URL。
现在结果如下: http://domain.com/Live/Schedule?date=2013-03-29
它当然应该像这样正确地产生它: http://domain.com/Live/Schedule/2013-03-29
My Global.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);
}
我做错了什么?