0
我想讓MVC產生一個正確的URL。使用得到的Mvc路線無效
現在事實證明這樣的: http://domain.com/Live/Schedule?date=2013-03-29
它當然應該正確地產生這樣的: http://domain.com/Live/Schedule/2013-03-29
我的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>
}
結果:
public ActionResult Schedule(string date)
{
var model = getModel(date);
return View(model);
}
我在做什麼錯了:接受輸入
<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>
控制器?