Reputation: 271
i am woring on asp.net mvc3 and have a problem that i want to redirect user to any dynamic link which user entered , how to do this my current working is following
i tried by 2 types
1.
Controller
if (condition == true)
{
string Link ="www.google.com"; // suppose this is the url entered by user
ViewData["link"] = Link;
return PartialView("REdirectToLink");
}
REdirectToLink.cshtml
@{
string link = ViewData["link"].ToString();
}
<script type="text/javascript" >
var tlink = "@link";
window.location.replace(tlink);
</script>
2.
Controller
if (condition == true)
{
string Link ="www.google.com"; // suppose this is the url entered by user
return RedirectPermanent(Link);// also tried return Redirect(Link);
}
how to do this , thanks in advance !
Upvotes: 1
Views: 4450
Reputation: 1924
Just use:
string link = "http://www.google.com";
return Redirect(link);
Upvotes: 3