views:

214

answers:

2

Hi,

I want to implement a Jquery thickbox to show an image that is generated from my database in ASP.Net MVC. My link looks roughly like this:

<a href="<%=Url.Action("ShowPhoto", "Item", new { id = pic.pictureID })  %>" class="thickbox"><img src="<%= Url.Action( "ShowThumbnail", "Item", new { id = pic.pictureID  } ) %>" alt="" width="100px" /></a>

However, I'm having errors popping out caused by the Url.Action link.

Someone please help me!!

EDIT: Sorry, I forgot to put the error in.

In the Visual Studio:

NullReferenceException was unhandled by user code. Object reference not set to an instance of an object. (This is highlighted in UnitofWork.CurrentUnitOfWork.Dispose();)

In my error log:

System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (&). at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplication.ValidateRequestExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

System.Web.HttpException (0x80004005): File does not exist. at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

A: 

I don't think that this is to do with thickbox, but can you confirm that your two snippets of code (below) actually render a url?

<%=Url.Action("ShowPhoto", "Item", new { id = pic.pictureID })  %>

and

<%= Url.Action("ShowThumbnail", "Item", new { id = pic.pictureID }) %>
Dan Atkinson
Yes it does. It gives http://localhost:3071/Item/ShowPhoto/32 andhttp://localhost:3071/Item/ShowThumbnail/32
luminousSpark
Okay. I can only assume that ShowThumbnail returns an ImageResult, or something like that. Does the image display correctly when you open it in a browser?
Dan Atkinson
Yup, it's actually an ImageResult. And yes, without the thickbox, it's displaying correctly.
luminousSpark
+1  A: 

I let the Html.ActionLink helper render out the links that include code for me, like this:

    <%=Html.ActionLink(Resources.Localize.Routes_WidgetsCreate, "Create", "Widget",  new { modal = true },
                                      new
                                        {
                                            rel = "shadowbox;height=600;width=700",
                                            title = Resources.Localize.Routes_WidgetsCreate
                                        })%>

Explanation: Resources.Localize.Routes_WidgetsCreate is a reference to Resources class to get localized string, "Create" is the controller action, "Widget" is the controller, "new { model = true }" is QueryString parameter, "new { rel ... } " these are the tag attributes.

This is an example of a Shadowbox link that opens modal window with the contents that ~/Widget/Create returns.

HTH

mare
Thanks for that. However, I'd like to give thickbox a go first before trying this one out. ^^Would this apply on thickbox though? And sorry for beig a noob, but how do you make a resource class to get localized string?
luminousSpark
This would apply to Thickbox too, of course, replace "rel" with "class" if that's what Thickbox JS picks up and also check out the "height" and "widght" attributes because those too can be different in Thickbox. With regards to Resources, just add a new RESX file in the App_GlobalResources folder, compile it and you should be able to access the string from anywhere in your code (be it Views/Controllers/Classes) by using this convention ResourceNamespace.ResourceClass.ResourceStringId.
mare