Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. ASP.NET MVC - Can't seem to get Html.ActionLink to route to Webform page

ASP.NET MVC - Can't seem to get Html.ActionLink to route to Webform page

Scheduled Pinned Locked Moved ASP.NET
asp-nethelpcsharpjavascripthtml
5 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Mujica
    wrote on last edited by
    #1

    I have a MVC 4 application (with jQuery Mobile) working and I'm trying to build some Administrative pages which will be implemented as WebForms. The problem I am having is that I can't seem to get the Html.ActionLink to send the user to those admin pages. The admin pages reside in a /AdminUtils folder off the root of the application. Based on some searching, I've added the following to my Global.asax.vb

    Sub Application_Start()
    AreaRegistration.RegisterAllAreas()

        WebApiConfig.Register(GlobalConfiguration.Configuration)
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters)
        RouteConfig.RegisterRoutes(RouteTable.Routes)
        BundleConfig.RegisterBundles(BundleTable.Bundles)
    End Sub
    
    Sub RegisterRoutes(Routes As RouteCollection)
        Routes.IgnoreRoute("AdminUtils/{\*pathInfo}")
    
        '1) Route name
        '2) Route URL
        '3) Physical File
    
        Routes.MapPageRoute("ReportRoute", "AdminUtils/{someparam}", "~/AdminUtils/{someparam}.aspx")
    
        'Routes.MapPageRoute("DummyRoute", "AdminUtils", "~/AdminUtils/WebForm1.aspx")
    
    End Sub
    

    In my Index.vbhtml page I have the following:

    @Html.ActionLink("Admin Link", "AdminUtils", New With {.Page = "WebForm1.aspx"})

    However, if I hover over the link, it indicates that it wants to route to:

    http://localhost:63163/Home/AdminUtils?Page=WebForm1.aspx

    If I use a standard hyperlink,

    <a href="~/AdminUtils/WebForm1.aspx" title="Form 1">Webform1 Here </a>

    the browser is directed to the page and WebForm1.aspx displays as normal. I'm thinking it has something to do with the Routing, but I just don't know what to do. Thank you in advance for you help. David

    K L 2 Replies Last reply
    0
    • D David Mujica

      I have a MVC 4 application (with jQuery Mobile) working and I'm trying to build some Administrative pages which will be implemented as WebForms. The problem I am having is that I can't seem to get the Html.ActionLink to send the user to those admin pages. The admin pages reside in a /AdminUtils folder off the root of the application. Based on some searching, I've added the following to my Global.asax.vb

      Sub Application_Start()
      AreaRegistration.RegisterAllAreas()

          WebApiConfig.Register(GlobalConfiguration.Configuration)
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters)
          RouteConfig.RegisterRoutes(RouteTable.Routes)
          BundleConfig.RegisterBundles(BundleTable.Bundles)
      End Sub
      
      Sub RegisterRoutes(Routes As RouteCollection)
          Routes.IgnoreRoute("AdminUtils/{\*pathInfo}")
      
          '1) Route name
          '2) Route URL
          '3) Physical File
      
          Routes.MapPageRoute("ReportRoute", "AdminUtils/{someparam}", "~/AdminUtils/{someparam}.aspx")
      
          'Routes.MapPageRoute("DummyRoute", "AdminUtils", "~/AdminUtils/WebForm1.aspx")
      
      End Sub
      

      In my Index.vbhtml page I have the following:

      @Html.ActionLink("Admin Link", "AdminUtils", New With {.Page = "WebForm1.aspx"})

      However, if I hover over the link, it indicates that it wants to route to:

      http://localhost:63163/Home/AdminUtils?Page=WebForm1.aspx

      If I use a standard hyperlink,

      <a href="~/AdminUtils/WebForm1.aspx" title="Form 1">Webform1 Here </a>

      the browser is directed to the page and WebForm1.aspx displays as normal. I'm thinking it has something to do with the Routing, but I just don't know what to do. Thank you in advance for you help. David

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      I've not done this work directly, but the actionlink feels wrong, as it is accessing a separate, non-MVC app. I'd stick with the plain hyperlink when referring out.

      David Mujica wrote:

      outes.MapPageRoute("ReportRoute", "AdminUtils/{someparam}", "~/AdminUtils/{someparam}.aspx")

      Again this feels wrong: you are producing a route map to an external, non-MVC application. It also contradicts the ignore route (which I think is right). Again you have to mod this all through my inexperience at having embedded non-MVC apps......

      Sort of a cross between Lawrence of Arabia and Dilbert.[^]
      -Or-
      A Dead ringer for Kate Winslett[^]

      R 1 Reply Last reply
      0
      • D David Mujica

        I have a MVC 4 application (with jQuery Mobile) working and I'm trying to build some Administrative pages which will be implemented as WebForms. The problem I am having is that I can't seem to get the Html.ActionLink to send the user to those admin pages. The admin pages reside in a /AdminUtils folder off the root of the application. Based on some searching, I've added the following to my Global.asax.vb

        Sub Application_Start()
        AreaRegistration.RegisterAllAreas()

            WebApiConfig.Register(GlobalConfiguration.Configuration)
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters)
            RouteConfig.RegisterRoutes(RouteTable.Routes)
            BundleConfig.RegisterBundles(BundleTable.Bundles)
        End Sub
        
        Sub RegisterRoutes(Routes As RouteCollection)
            Routes.IgnoreRoute("AdminUtils/{\*pathInfo}")
        
            '1) Route name
            '2) Route URL
            '3) Physical File
        
            Routes.MapPageRoute("ReportRoute", "AdminUtils/{someparam}", "~/AdminUtils/{someparam}.aspx")
        
            'Routes.MapPageRoute("DummyRoute", "AdminUtils", "~/AdminUtils/WebForm1.aspx")
        
        End Sub
        

        In my Index.vbhtml page I have the following:

        @Html.ActionLink("Admin Link", "AdminUtils", New With {.Page = "WebForm1.aspx"})

        However, if I hover over the link, it indicates that it wants to route to:

        http://localhost:63163/Home/AdminUtils?Page=WebForm1.aspx

        If I use a standard hyperlink,

        <a href="~/AdminUtils/WebForm1.aspx" title="Form 1">Webform1 Here </a>

        the browser is directed to the page and WebForm1.aspx displays as normal. I'm thinking it has something to do with the Routing, but I just don't know what to do. Thank you in advance for you help. David

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        With MVC, the Html.ActionLink() does not link to a view. It creates a link to a controller action. If it's just a static link I would just put it as part of the html.

        D 1 Reply Last reply
        0
        • K Keith Barrow

          I've not done this work directly, but the actionlink feels wrong, as it is accessing a separate, non-MVC app. I'd stick with the plain hyperlink when referring out.

          David Mujica wrote:

          outes.MapPageRoute("ReportRoute", "AdminUtils/{someparam}", "~/AdminUtils/{someparam}.aspx")

          Again this feels wrong: you are producing a route map to an external, non-MVC application. It also contradicts the ignore route (which I think is right). Again you have to mod this all through my inexperience at having embedded non-MVC apps......

          Sort of a cross between Lawrence of Arabia and Dilbert.[^]
          -Or-
          A Dead ringer for Kate Winslett[^]

          R Offline
          R Offline
          RJOberg
          wrote on last edited by
          #4

          As Keith said, use the href. Spent some time working on this in an app myself. And after some digging, it seems ActionLink is for routing to internal links within your MVC application. You can create an actionlink that uses a controller to redirect the user, but that seems like a lot of work to get a simple action done.

          public ActionResult MyController(){
          return Redirect("http//www.mysite.com");
          }

          1 Reply Last reply
          0
          • L Lost User

            With MVC, the Html.ActionLink() does not link to a view. It creates a link to a controller action. If it's just a static link I would just put it as part of the html.

            D Offline
            D Offline
            David Mujica
            wrote on last edited by
            #5

            just wanted to let everyone who responded that I appreciate your help. After thinking about it for a while, I think I need to use a plain old, hyperlink. Yep. Thanks again.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups