-1

I have product controller and two methods edit and fileupload. what should I do in my route config to make these two work.

Product/6 (for editing productid 6)

Product/Fileupload (for uploading file).

my current route in routeconfig is as follows:

     routes.MapRoute(
        name: "editProducts",
        url: "Product/{id}",
        defaults: new { controller = "Product", action = "Edit", id=UrlParameter.Optional }
    );
Cœur
  • 37,241
  • 25
  • 195
  • 267
Learner
  • 1,277
  • 3
  • 15
  • 34

3 Answers3

1

Add the following routes (in this order) before the default. I have assumed that you always need an ID to edit so the id parameter is not optional (but you could make it so) and I was not sure if you needed to pass a parameter to the FileUpload method

routes.MapRoute(
  name: "Upload",
  url: "Product/FileUpload/{id}",
  defaults: new { controller = "Product", action = "FileUpload", id = UrlParameter.Optional }
);

routes.MapRoute(
  name: "editProducts",
  url: "Product/{id}",
  defaults: new { controller = "Product", action = "Edit" }
);
0

Try following:

routes.MapRoute(
        name: "editProducts",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Product", action = "Edit", id=UrlParameter.Optional }
    );
Hiren Kagrana
  • 912
  • 8
  • 21
0

Add tahe following routes by same order before the default.

    routes.MapRoute(
        name: "fileupload",
        url: "{controller}/{action}",
        defaults: new { controller = "Product", action = "Fileupload"}
    );

    routes.MapRoute(
        name: "editProducts",
        url: "Product/{id}",
        defaults: new { controller = "Product", action = "Edit", id=UrlParameter.Optional }
    );
Francois Borgies
  • 2,378
  • 31
  • 38
Sujit Patil
  • 183
  • 4