MVC 3 - img alt HTML tag?
I have the following HTML from MVC1.
<img alt="<%= Html.Encode(item.Name) %>" src='<%= this.Url.Action("Image",
"Products") + "/" + item.ID.ToString()%>' width="64" height="64" />
How would I use this for MVC 3, I have tried the following it's not working...
<img alt=" @Html.Encode(item.Name)" src='<@this.Url.Action(("Image",
"Products")) + "/" + Picture1.SubProductCategoryID.ToStri开发者_Go百科ng()>'
width="64" height="64" />
Thanks in advance
I'm making some assumptions but:
<img alt="@item.Name"
src='@(Url.Action("Image", "Products") + "/" + Picture1.SubProductCategoryID.ToString())'
width="64"
height="64" />
If you have a statement instead of a simple action invocation, you need to surround the entire statement with parens ()
. Also, you needed to drop the <>
around the helper. @SLaks is right about not needing the Html.Encode
, too.
Change your src
to
src="@Url.Action("Image", "Products")/@Picture1.SubProductCategoryID"
Also, don't call Html.Encode
; Razor does this for you.
精彩评论