ポップアップウィンドウに画像を表示するためのプラグインを使用しようとしています。私はThickbox、fancyboxを試しましたが、うまくいきません。
私のURLに問題があると思います。
これは私のコードです:
<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 である必要があると思います。ファンシーボックスが機能するようにコードを書き直すにはどうすればよいですか?
これは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
});
}