开发者

how to read value from URL? asp.net mvc

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 abo开发者_Go百科ve, and insert it instead id = "id" - > id = "09251a7f-c362-4ed9-98e2-c9d555aaaf4f" ??


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" 
/>


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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜