Url.Action不会调用操作

时间:2012-01-05 12:03:56

标签: asp.net-mvc

我有以下代码:

查看:

<li>
    <a href="<%=bannerImage.Url%>">
    <img src='<%=Url.Action("GetImage", "Image", new {imageName = bannerImage.Image})%>'></a>
</li>

控制器:

public ActionResult GetImage(string imageName)
{
    var folder = ConfigurationManager.AppSettings["ImagesFolder"];
    return File(folder + imageName, "image/jpg");
}

GetImage永远不会开火 哪里出错?

FireBag消息:"NetworkError: 500 Internal Server Error - http://localhost:8178/error?action=GetImage&controller=Image&imageName=9bbc2035-f753-4212-985b-b6e689150529.Jpeg"

修改
我的路线:

routes.MapPageRoute("Error", "error", "~/Error.aspx");

            routes.MapRoute(
                "Cinema Full", // Route name
                "{city}/cinema/{id}/{action}/{subaction}", // URL with parameters
                new { city = "astana", controller = "Cinema", action = "Overview", subaction = UrlParameter.Optional }, // Parameter defaults
                new { city = new CityConstraint() }
            );

            routes.MapRoute(
                "Cinema", // Route name
                "{city}/cinema", // URL with parameters
                new { city = "astana", controller = "Cinema", action = "Index" }, // Parameter defaults
                new { city = new CityConstraint() }
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{subaction}", // URL with parameters
                new { controller = "Home", action = "Index", subaction = UrlParameter.Optional } // Parameter defaults
            );

1 个答案:

答案 0 :(得分:0)

我认为url helper调用Url.Action(“GetImage”,“Image”,new {imageName = bannerImage.Image})使用第一个路由配置生成错误的URL。尝试添加路线(在开头):

    routes.MapRoute(
        "ImageGen", // Route name
        "images/{imageName}", // URL with parameters
        new { controller = "Image", action = "GetImage"} // Parameter defaults
    );