简体   繁体   English

将模型元素值添加到@ Url.Content问题

[英]Add model element value to @Url.Content issue

I just to add some model elemen value to Url.Content and don't know how to do it. 我只是在Url.Content中添加一些模型元素值,并且不知道该怎么做。

Any clue? 有什么线索吗?

Thank you! 谢谢!

Those lines don't work... 这些行不起作用...

<img alt="" src="@Url.Content("~/Images/Houses/@(house.ImageFileName)")" />

<img alt="" src="@Url.Content("~/Images/Houses/@house.ImageFileName")" />

<img alt="" src="@Url.Content("~/Images/Houses/" + @house.ImageFileName + ")" />

You don't need the @ before your house object since you've already declared a code block with the first one at @Url . house object之前不需要@ ,因为您已经在@Url声明了第一个代码块。 But this is the best way below. 但这是下面的最佳方法。

Assuming house is a valid object in the context : 假设housecontext是有效object

<img alt="" src="@Url.Content(String.Format("~/Images/Houses/{0}", house.ImageFileName))" />

您也可以尝试

<img alt="" src="@Url.Content("~/Images/Houses/" + house.ImageFileName)" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM