MVC Server.Transfer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StevieMars
    New Member
    • Mar 2010
    • 21

    MVC Server.Transfer

    Hi All,

    I'm a newbie to MVC and have run into a situation where for example the user goes to url

    MySite/Category/?id=10

    If there are no products for categoryid 10 then I want to server.transfer to a generic product missing error page (keeping the URL the same). From what I understand about MVC I'm not able to just server.transfer so how would I do this?

    Thanks in advance,
    Steve
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Good question :)
    I'm curious to hear the answer when you find it :)

    In my quick googling I am under the impression that you are going to want to use the Controller.Redi rectToAction method.

    -Frinny

    Comment

    • StevieMars
      New Member
      • Mar 2010
      • 21

      #3
      ok found a solution that seems to do the job. If the product does not exist I execute the following code else I return the View as normal. This should work providing the action 'MissingProduct ' returns a View.
      Code:
      GenericController controller = new GenericController { ControllerContext = ControllerContext };
      controller.RouteData.Values["controller"] = "Generic";
      controller.RouteData.Values["action"] = "MissingProduct";
      return controller.MissingProduct();
      Last edited by Frinavale; Jul 21 '10, 07:39 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Sorry I couldn't have been more help.

        Thanks for sharing the solution :)

        Comment

        Working...