我无法在ASP.NET Core MVC中重定向到另一个网站。

huangapple go评论51阅读模式
英文:

I can't redirect to another website in ASP.NET Core MVC

问题

无法在ASP.NET Core MVC中重定向到另一个网站。我想要一个链接,可以重定向到另一个网站,但对我来说无效。

我尝试将链接(例如https://www.twitter.com/)简单地放在我的<a>标签的href="..."中,如下所示:

<a href="https://www.instagram.com/mclaren/" target="_blank">Twitter</a>

有没有任何原因它不起作用?我必须显示每个联系人的每个社交媒体链接(这些链接存储在我的数据库中的联系人表中),所以我需要这个工作并且高效运行。

谢谢!

英文:

I can't redirect to another website in ASP.NET Core MVC. I want to have a link that redirect to another website but it's not working for me.

I tried to put the link (e.g. https://www.twitter.com/) simply in the href=&quot;...&quot; of my &lt;a&gt; tag like this:

&lt;a href=&quot;https://www.instagram.com/mclaren/&quot; target=&quot;_blank&quot;&gt;Twitter&lt;/a&gt;

Is there any reason why it doesn't work? I have to display every socials (that are in my database in the table Contact) of every contact, so I need this to work and to work efficiently.

Thank you!

答案1

得分: 0

你可以尝试不同的方法:
在你的控制器中创建一个操作方法

public IActionResult RedirectExample()
{
    return Redirect("https://www.instagram.com/mclaren/");
}

然后在Razor页面中使用以下代码:

<a href="/Home/RedirectExample" target="_blank">Instagram</a>
英文:

You can try different approach :-
Create a Action method in you controller

public IActionResult RedirectExample()
{
    return Redirect(&quot;https://www.instagram.com/mclaren/&quot;);
}

and in razor page

&lt;a href=&quot;/Home/RedirectExample&quot; target=&quot;_blank&quot;&gt;Instagram&lt;/a&gt;

huangapple
  • 本文由 发表于 2023年5月26日 08:01:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76336884.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定