Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure how you're storing your data, but assuming you have the ID and the text in your data, rather than building a string with the Razor syntax in it, your view should contain all the necessary markup, using variables with the data in it.</p> <p>For example, if you had a partial view where your model was the image with properties Id and Description, your partial view would look like:</p> <pre><code>&lt;img src="@Url.Action("getImg", "Responses", new { id = Model.ID })" alt="@Model.Description"&gt; </code></pre> <p>Then when you pass in your object into the partial, it will render normally, without any funky parsing of Razor HTML.</p> <p><strong>EDIT</strong></p> <p>If I understand your edit, you are running some code to transform the <code>src</code> attribute of your <code>img</code> tag into what you want it to be. You are transforming it into a Razor string though, not to valid HTML - what you want to do is to actually build the image's URL when you're assigning the <code>src</code>, rather than later on when you're in the view.</p> <p>To do that, I believe this will get you going:</p> <pre><code>string imageUrl = RouteTable.Routes.GetVirtualPath( System.Web.HttpContext.Current.Request.RequestContext, new RouteValueDictionary(new { controller = "Responses", action = "getImg", id = Model.ID })).VirtualPath; </code></pre> <p>What this will do is build the MVC URL based on those parameters inside your code, so you can dump that straight into the <code>src</code> attribute. You may have to tweak this a bit if you're dealing with weird routing or anything like that - but I think it should work for a basic setup.</p> <p>If you're inside of a controller, I believe you can do <code>ControllerContext.RequestContext</code> or possibly even just <code>ControllerContext</code> instead of getting the static current one.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload