Paul
Paul

Reputation: 457

How to set image path dynamically in MVC 3 RAZOR

How to set image path dynamically for following:

<img src="/Images/Model" + @item.ModelImagePath />

"/Images/Model" this path is fixed, rest of the path comes from [ModelImagePath] column of Model DBTable.

Please guide me how to set the path dynamically in View.

And is there any Html helper tag to display image available in MVC RZOR?

Note: i have similar type of problem as described in

How to use/pass hidden field value in ActionLink

Upvotes: 7

Views: 17004

Answers (2)

Prashant Tyagi
Prashant Tyagi

Reputation: 11

If you have already saved the entire path into the table, follow it

<img src="@Url.Content(String.Format("{0}",item.ModelImagePath))"/>

or

<img src="@Url.Content(item.ModelImagePath)" style="width:100px;height:100px"/>

Upvotes: 1

David Peden
David Peden

Reputation: 18434

<img src="@Url.Content(String.Format("~/Images/Model/{0}", item.ModelImagePath))"

Upvotes: 21

Related Questions