0

I have a MVC application hosting multiple SSRS reports, each on a separate WebForm. These reports are all tied together on the Index View in the Home folder where I got href links to direct the user to the report they want.

The trouble now is I am trying to create a button on these WebForms which would redirect the user back to the Index view. I searched on Stack Overflow for guidance and have come up with multiple checked answers and attempted to try them out. However, none of them seem to redirect me to the desired page. Instead, they simply redirect me to the same page I am on.

I have tried the following solutions:

It seems to me that the problem lies in my routing, however, I still don't understand enough about routing URLs to get this to work out.

For context, this is my first time writing a C# MVC application. I have and am currently reading documentation and code snippets on the web about best practices and such, but with no available guidance from my coworkers and less than 2 weeks of experience, it's hard to decipher what are the dos and don'ts. Any help and tips are much appreciated!

An example of a redirect would be from the UserManagement.aspx (~/WebForms/IT/UserManagement.aspx) page to the Index.cshtml (~/Views/Home/Index.cshtml) page

Here is what I currently have:

My RouteCongif.cs

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = 
                    UrlParameter.Optional });
        }
UserManagement.aspx


<div>
    <asp:Button ID="BackButton" runat="server" Text="Back" />
</div>

The BackButton_Click function in UserManagement.aspx.cs (CodeBehind)

protected void BackButton_Click(object sender, EventArgs e)
        {
            UrlHelper urlHelp = new 
            UrlHelper(HttpContext.Current.Request.RequestContext);
            Response.Redirect(urlHelp.Action("Index", "Home"), false);
        }
s1o3urn
  • 1
  • 1
  • Did you try RedirectToAction? https://learn.microsoft.com/en-us/previous-versions/aspnet/dd470154(v=vs.108) – David C Aug 09 '19 at 23:18
  • I tried Response.Redirect since I'm on a WebForm. RedirectToAction gives me does not exist in the current context error even if I have the using system.web.mvc mention. If i'm not mistaken RedirectToAction is used in a cshtml page. – s1o3urn Aug 12 '19 at 20:48

1 Answers1

0

in controller you can use RedirectToAction or Return View("View Name"). from view write javascript as window.location.href=/Controller/View on button click

Nijin P J
  • 1,302
  • 1
  • 9
  • 15