英文:
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="..."
of my <a>
tag like this:
<a href="https://www.instagram.com/mclaren/" target="_blank">Twitter</a>
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("https://www.instagram.com/mclaren/");
}
and in razor page
<a href="/Home/RedirectExample" target="_blank">Instagram</a>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论