0

its a full url:

http://localhost:64075/WPMManagement/Image/id=09251a7f-c362-4ed9-98e2-c9d555aaaf4f

it my asp.net mvc view:

<img height="660px" 
     width="430px" 
     src="<%= Url.Action("WebPageImage", "WPMManagement", new { id = id }) %>"
     alt="bild mit webseiten version" />

how can I read id from URL which above, and insert it instead id = "id" - > id = "09251a7f-c362-4ed9-98e2-c9d555aaaf4f" ??

4 Answers 4

4

If the id is part of your route data:

<img 
    height="660px" 
    width="430px" 
    src="<%= Url.Action("WebPageImage", "WPMManagement", new { id = ViewContext.RouteData.Values["id"] }) %>" 
    alt="bild mit webseiten version" 
/>
Sign up to request clarification or add additional context in comments.

Comments

1

Well, from what I can see that URL does not contain any querystrings:

http://localhost:64075/WPMManagement/Image/id=09251a7f-c362-4ed9-98e2-c9d555aaaf4f

If you'd have a ?id= you'd be able to write Request["id"] in your view, but in the case of the abovementioned URL this will return null. In other words, the correct url in order to use Request["id"] is:

http://localhost:64075/WPMManagement/Image/?id=09251a7f-c362-4ed9-98e2-c9d555aaaf4f

However, if you're Route indicates that the part after /Image/ is the Id, you can remove the id= all together, and the resulting URL would be:

http://localhost:64075/WPMManagement/Image/09251a7f-c362-4ed9-98e2-c9d555aaaf4f

This should enable you to get the Id of the current RouteValues dictionary

Comments

0

Request.QueryString["id"] will help :o)

2 Comments

should i write it in view inside id? like id=<% Request.QueryString["id"]%>?
Write it in your method behind. If you are using MVC3, then you can use the ViewBag like so: ViewBag.Id = Request.QueryString["id"];. But, it seems that adding it straight in seems to work as well.
0
<img height="660px" width="430px" src="<%= Url.Action("WebPageImage", "WPMManagement", new { id = Request.QueryString["id"] }) %>"
        alt="bild mit webseiten version" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.