redirecting from MVC view to ASPX page

时间:2015-09-14 15:46:03

标签: c# asp.net-mvc-4

I need to redirect from my MVC view to ASPX page. I need to show a link in MVC page and clicking the link should redirect me ASPX page. Below is my code

<td class="pr0">
    @Html.ActionLink("Add money now", "IsaAddMoney", "MyPortfolio", null, new {@class = "right-arrow button addmoneynow right"})
    @{ Response.Redirect("~/my-accounts/addmoney.aspx");}
</td>

The first line that is @HTML.ActionLink is the original which is redirecting to mvc page. I no more want this now. I now want to show the user similar link that displays Add money now and able to redirect the user as shown in the second line of code.However the second line of code redirects the page now to url path provided without displaying the source mvc page containing the link button.

2 个答案:

答案 0 :(得分:4)

You have two options. If you for some reason want to make it with a redirect (which I don't know why it would be required) you need to make an ActionLink to an MVC handler and in that handler do the redirect forward.

Otherwise you could just add a normal a tag with the desired location and leave it at that. There is no redirection needed for just going to another location and the Html.ActionLink is not doing any redirection, it is just outputting a normal a tag.

So the simplest way: <a href="~/my-accounts/addmoney.aspx">Add money now</a>

答案 1 :(得分:2)

You can redirect to anywhere from MVC action and you have to use RedirectResult for that. RedirectResult is a type of ActionResult.

For ex.

public RedirectResult RedirectToAspx()
{
  return Redirect("/pages/index.aspx");
}