我试图使用一些插件在弹出窗口中显示图像。我试过Thickbox,fancybox,但没有用。
我认为我的网址有问题。
这是我的代码:
<a href='@Url.Action("GetSchemaImage", "Hall", new {folderName = @Model.FolderName })' class="fancybox"><img src='@Url.Action("GetSchemaImage", "Hall", new {folderName = @Model.FolderName })'/></a>
这是控制器的操作:
public ActionResult GetSchemaImage(string folderName)
{
if(string.IsNullOrWhiteSpace(folderName))
return new EmptyResult();
var folder = ConfigurationManager.AppSettings["SchemasFolder"];
var path = Path.Combine(folder, folderName);
var schemaImage = Directory.GetFiles(path, "*.*").FirstOrDefault(s => s.EndsWith(".png") || s.EndsWith(".jpg"));
if (schemaImage != null)
return File(Path.Combine(path, schemaImage), "image/png");
return new EmptyResult();
}
这是生成的标记:
<a class="fancybox" href="/Hall/GetSchemaImage?folderName=marineclub"><img src="/Hall/GetSchemaImage?folderName=marineclub"></a>
正如我所说,我认为 URL: 中的问题/Hall/GetSchemaImage?folderName=marineclub
。插件无法理解这一点。
我认为 URL 必须如下:/Hall/GetSchemaImage/marineclub。我怎样才能重写我的代码以使 fancybox 可以工作?
这是javascript代码:
$(function () {
$(".fancybox").fancybox({ type: image });
})
非常感谢。
更新: 这是所有路线:
public static void RegisterRoutes(RouteCollection routes)
{
var entryRoute = new PageEntry("page/{name}/",
new RouteValueDictionary(
new
{
controller = "DynamicPage",
action = "Index",
name = String.Empty
}),
new RouteValueDictionary(new { name = @".+" }),
new MvcRouteHandler());
routes.Add("display-page",
entryRoute);
routes.MapRoute("Event Overview", "{city}/{type}/{id}",
new {city="astana", controller = "BaseEvent", action = "EventOverview"}, 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(
"Concert", // Route name
"{city}/concert", // URL with parameters
new { city = "astana", controller = "Concert", action = "Index" }, // Parameter defaults
new { city = new CityConstraint() }
);
routes.MapRoute(
"Club", // Route name
"{city}/club", // URL with parameters
new { city = "astana", controller = "Club", action = "Index" }, // Parameter defaults
new { city = new CityConstraint() }
);
routes.MapRoute(
"Children", // Route name
"{city}/children", // URL with parameters
new { city = "astana", controller = "Children", action = "Index" }, // Parameter defaults
new { city = new CityConstraint() }
);
routes.MapRoute(
"Sport", // Route name
"{city}/other", // URL with parameters
new { city = "astana", controller = "Other", action = "Index" }, // Parameter defaults
new { city = new CityConstraint() }
);
routes.MapRoute(
"Theater", // Route name
"{city}/theater", // URL with parameters
new { city = "astana", controller = "Theater", action = "Index" }, // Parameter defaults
new { city = new CityConstraint() }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Activate",
"Account/Activate/{username}/{key}",
new
{
controller = "Account",
action = "Activate",
username = UrlParameter.Optional,
key = UrlParameter.Optional
});
routes.MapRoute(
"ResetPassword",
"Account/Reset/{email}/{key}",
new
{
controller = "Account",
action = "Reset",
email = UrlParameter.Optional,
key = UrlParameter.Optional
});
}