2

i've created a upload form for 1 image. after the image is stored on the filesystem i want to refresh the partial view (which then should display the image).

After uploading a image, jQuery runs the Url.Action but doesn't render the partial view which gets returned from the Action "WebAuftragImageRefresh"...

Maybe you have an idea?

Regards, float

BTW. Why is the code-block not ignoring html tags?

View: http://codepaste.net/co1gu9 Partial-View: http://codepaste.net/1rxq2d Controller: http://codepaste.net/j8kugj

4
  • How does the controller action WebAuftragImageRefresh look like? Please post your server side code as well. Also what happens when you analyze with FireBug? Is there some error? Does the server send the correct partial HTML? Commented Jan 17, 2011 at 13:53
  • There is no error in Firebug. I get html back, but the file extension is missing: <h3>Bild zum Auftrag</h3><p align="center"> <img src="/Admin/WebAuftragFSImage/0d3b2992-aa72-4b24-8016-a2e9764579b5" width="300" height="300" alt="Vorschau Bild"/></p> Commented Jan 17, 2011 at 14:34
  • well,i think the Url.Action in the partial view runs only at the first time it gets called. Maybe Url.Action is the wrong method? Commented Jan 17, 2011 at 14:39
  • I checked it again. When i'm not displaying a default picture, the jQuery code sets the html whats returned by the controller action. why doesn't this work with a default picture? Commented Jan 19, 2011 at 12:38

1 Answer 1

1

In your view you're doing:

$.get('@Url.Action("WebAuftragImageRefresh", ViewContext.RouteData.Values["Controller"].ToString(), new { id = ViewBag.AuftragGUID })', {...

But where exactly is this piece of jQuery code getting the ViewBag.AuftragGUID from which is actually being set in the WebAuftragImageRefresh ActionResult?

Sign up to request clarification or add additional context in comments.

4 Comments

Hello, The ViewBag.AuftragGUID is set in the Controller Action create. This action calls the create view. the create view calls then the partial view for the picture upload (_Bildupload.cshtml). The partial view _Bildupload calls then the partial view _Bild for showing the picture. Here you can find the code with the updated controller actions: codepaste.net/j8kugj
The partial view _Bild.cshtml shows a dummy image. The jQuery should then update this image with the uploaded image from the user.
Ok, sounds reasonable, then it might be that the image is being cached. What if you say: <img src="@Url.Action("WebAuftragFSImage", ViewContext.RouteData.Values["Controller"].ToString(), new { id = ViewBag.AuftragGUID, now=DateTime.Now.ToString("yyyyMMddHHmmssffff") })" width="300" height="300" alt="Vorschau Bild"/> This add's a unique value to your src URL, and should prevent your image from caching.
You are right! With this unique value it works perfekt :-) Thanks for your help!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.