如何从控制器在MVC 4返回URL字符串控制器 [英] How to return Url string from Controller a controller in mvc 4
问题描述
请我试图动态生成我的网址超链接在我的MVC应用程序。
Please i am trying to generate my Url hyperlink dynamically in my MVC Application.
<a href='http://facebook.com/myPage'>Facebook</a>
上面的链接带我到我的Facebook主页。我希望能够更改URL后面作为页面名称没有决定。所以我试图
The above link takes me to my facebook home page. I want to be able to change the url later on as the page name is not decided. So i tried
<a href='@Url.Action("GetFaceBookLink", "Home")'>Facebook</a>
在我的控制器
public ActionResult GetFaceBookLink()
{
string facebook = repository.SystemSettings.FirstOrDefault().FacebookLink;
return this.Content(facebook);
}
我的字符串的Facebook = http://facebook.com/mypage 。我想被redicted到我的Facebook主页,USAL。然而,当我点击,它返回一个黑色pagewithout重定向的URL字符串。请我怎么重定向?我如何实现这一目标?任何帮助将是AP preciated。
My string facebook = "http://facebook.com/mypage" . I want to be redicted to my facebook home page as usal. However, when i clicked, it returns the string url in a black pagewithout redirecting . Please how do i redirect ? how do i achieve this ? Any help would be appreciated.
推荐答案
您需要 Html.Action
助手在这里:
&LT; A HREF =@ Html.Action(GetFaceBookLink,家),'&GT; Facebook和LT; / A&GT;
Url.Action
不来电的动作,它会生成使用控制器和动作名称网址
Url.Action
do not calls action, it generates url using Controller and Action name
这篇关于如何从控制器在MVC 4返回URL字符串控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!