开发者

How to use @ inside href of anchor tag in ASP.NET MVC?

In my static website 开发者_如何学JAVAwhich is built in ASP.NET MVC, I'm using social media accounts in a Razor view. I'm getting an error as shown below when using this code:

<li><a class="youtube" href="https://youtube.com/@techiewords" target="_blank">
<i class="fab fa-youtube"></i></a></li>

Screenshot of the error I get:

How to use @ inside href of anchor tag in ASP.NET MVC?

How to avoid this error?

Tried to fix this error with an escape sequence by using @@.


How to avoid this error?

You can initialize an C# valiable and then assign the value that is "@techiewords" on that variable. Finally call the variable within {@variable} this should resolve the error. You can achieve in following way:

@{
    ViewData["Title"] = "Create";
    var urlSpecialCharacter = "@techiewords";
}

<li><a class="youtube" href="https://youtube.com/{@urlSpecialCharacter}" target="_blank"><i class="fab fa-youtube"></i>Test URL</a></li>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜