I trying to use the some plugin for show images in popup window.
I tryed Thickbox, fancybox, but not works.
I think the problem in my URL.
This is my code:
<a href='@Url.Action("GetSchemaImage", "Hall", new {folderName = @Model.FolderName })' class="fancybox"><img src='@Url.Action("GetSchemaImage", "Hall", new {folderName = @Model.FolderName })'/></a>
This is controller’s action:
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();
}
This is generated markup:
<a class="fancybox" href="/Hall/GetSchemaImage?folderName=marineclub"><img src="/Hall/GetSchemaImage?folderName=marineclub"></a>
As I said, I think the problem in URL: /Hall/GetSchemaImage?folderName=marineclub. The plugin can’t understand this.
I think URL must be the following: /Hall/GetSchemaImage/marineclub.
How can I rewrite my code that the fancybox can work?
This is javascript code:
$(function () {
$(".fancybox").fancybox({ type: image });
})
Big thanks.
UPDATE:
This is all routes:
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
});
}
So if you want a URL like this :
/Hall/GetSchemaImage/marineclubyou could do one of two things:Change your action method like this so it matches your default route:
So now
Hall/GetSchemaImage/marineclub=>{controller}/{action}/{id}OR
Add a route to match your controller: