1
如何添加一條路線來捕獲指向控制器的所有URL,以便將控制器名稱後的所有參數轉換爲單個參數字符串?如何添加一個路徑到MVC3轉換部分的URL到一個參數?
我需要這種映射:
URL /Image/foo.png -> Controller: Image, Action: Index, argument "foo.png"
URL /Image/A/foo.png -> Controller: Image, Action: Index, argument "/A/foo.png"
URL /Image/A/B/foo.png -> Controller: Image, Action: Index, argument "/A/B/bar.png"
這是我的內ImageController
public ImageResult Index(string file)
{
// foo bar
}
行動這是我試過
routes.MapRoute(null, "Image/{file*}", new { controller = "Image", action = "Index" });
URL /Image/baz.png
作品,文件是「 baz.png」。網址/Image/A/foo.png
不起作用,我的操作不受影響。
太棒了,謝謝。我喜歡它,當我可以用一個角色提交來解決問題時:D。 – Nenotlep