4
我有一個問題,MVC-3爲我生成傳出路由。問題ViewBag和路由(MVC 3 - RC2)
這是頁面的我在這兩種方案地址:http://localhost:1283/Conflict/Create/1200/300
這裏有地圖路線:
routes.MapRoute(
null, // Route name
"{controller}/{action}/{custId}/{projId}", // URL with parameters
null, // Parameter defaults
new { custId = @"\d+", projId = @"\d+" }
);
routes.MapRoute(
null, // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
方案1:
從控制器:
public ActionResult Create(int custId, int projId)
{
return View();
}
從視圖:
@Html.ActionLink("Back to List", "Index", "Conflict", new { custId = ViewBag.custId, projId = ViewBag.projId }, null)
生成的結果鏈接。
http://localhost:1283/Conflict?custId=1200&projId=300
如果我改變控制器代碼如下:
public ActionResult Create(int custId, int projId)
{
ViewBag.custId = custId;
ViewBag.projId = projId;
return View();
}
我並沒有在視圖中的任何改變,只加這兩條線的控制器和下面的鏈接創建:
http://localhost:1283/Conflict/Index/1200/300
缺少什麼我在這裏?這是一貫的行爲,我能夠在我的應用程序的其他領域重現這一點。 「解決方案」是顯而易見的,但我的問題是爲什麼?
我無法在我的機器上重現此行爲!奇怪 – swapneel 2011-03-08 20:39:56
索引操作方法還是創建?在你的actionlink中,第二個參數是「Index」? – 2011-03-17 12:54:32