1

I'm using a form and subsequently an action to redirect to another page. Problem is the action redirect function always redirects with a query string and not a full path. The end url is: localhost/Get?Description="ddd"&Id=555 Whereas I'd like it to be: localhost/Get/ddd/222

Here is my code: My routes:

  routes.MapRoute(
            "Create", // Route name
            "{controller}/{action}", // URL with parameters
            new
            {
              controller = "Home"
            } // Parameter defaults
           );

  routes.MapRoute(
                  "Get", // Route name
                  "{controller}/{action}/{Description}/{id}/", // URL with parameters
                  new
                  {
                    controller = "Home",
                    action = "Get",
                    Description = UrlParameter.Optional,
                    id = UrlParameter.Optional
                  } // Parameter defaults
                 );`

The form fills in the description and id and fires the create action, where i'm redirecting to the get action:

    public ActionResult Create(string desc,string id)
    {
      System.Web.Routing.RouteValueDictionary route = new System.Web.Routing.RouteValueDictionary(new { Description = desc, Id = id });

      return RedirectToAction("Get",route);
    }

Finally the get action is fired.

    public ActionResult Get(String Description,String Id)
    { return View() }

Please help..

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

Probably you need to generate a virtual path with RouteTable.Routes.GetVirtualPath. Please reference this article.

Kirill
  • 3,028
  • 1
  • 17
  • 18