I am having a hard time figuring out how to redirect to an outside source.
in my code, 开发者_StackOverflowI have
<%= Html.ActionLink("New Name Search", "Index") %>
which will allow me to navigate within the code.
how do I redirect to ...google for example?
<a href="http://www.google.com">google</a>
The purpose of the ActionLink helper is to generate links that will direct the user to a controller action that you've defined.
If you want to navigate the user to an outside source you should just use a regular anchor tag.
Response.Redirect("http://google.com/");
(It's not really MVC-specific, by the way)
If you are redirecting from your controller (or action filter, etc.) you can use the RedirectResult
as your ActionResult
type:
RedirectResult("http://www.google.com");
This is essentially doing a Response.Redirect
, but is the preferred way of sticking with ASP.NET MVC conventions.
If you are just creating a link inside a View
, just use <a href="http://www.google.com">Click to go to Google</a>
.
"Redirecting" means many things.
If you just want to show a link that redirects the user to another URL you can use the anchor tag normally in you templates.
<a href="http://www.google.com">google</a>
Now, if you want to redirect the user within the controller, call the Redirect Method.
Result("http://www.google.com");
精彩评论