简体   繁体   中英

Object to string using Razor?

Is there an Razor method that will allow to put "object to string" inside html like:

<a href="http://@Model.x.y">Anchor</a>

Or do I have to use something like that and change my model?

c# object to string to display it in text format

Thanks

if the link you are passing from your model is a string the correct syntax would be

 <a href="@Html.Raw(@Model.x.y))">Anchor</a>

or

<a href=@Html.Raw("http://www." + @Model.x.y))>Anchor</a>

This way you are correctly parsing any special characters which might occur in the link like & or =

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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