c# - Using Route Attributes In ASP.NET MVC 5 With Areas -


this question pertains asp.net mvc 5.

i'm trying use hyphens in urls using route attributes, i'm not having luck getting work. i'm using question , this msdn blog reference. urls want have are:

/my-test/ /my-test/do-something 

when build project , bring page i'm testing in browser, i'm getting 404 error. here code have far:

// routeconfig.cs public class routeconfig {     public static void registerroutes(routecollection routes)     {         routes.ignoreroute("{resource}.axd/{*pathinfo}");         routes.mapmvcattributeroutes();         arearegistration.registerallareas();         ...     } }  // mytestcontroller.cs - note: file in area [routearea("mytest")] [routeprefix("my-test")] [route("{action=index}")] public class mytestcontroller : controller {     [route("~/do-something")]     public jsonresult dosomething(string output)     {         return json(new         {             output = output         });     }      [route]     public viewresult index()     {         return view();     } }  // index.cshtml <script>     $(document).ready(function () {          // i'm using ajax call test dosomething() controller.         // div1 should display "hello, world!"         $.ajax({             datatype: "json",             type: "post",             url: "/product-management/do-something",             data: {                 output: "hello, world!"             }         }).done(function (response) {             $("div1").html(response.output);         });     }); </script> <div id="div1"></div> 

when created area, area registration file created , had route information in file, according msdn blog, can remove file , rely entirely upon route attributes.

i figured out. class needed following routeareaattribute:

[routearea("mytest", areaprefix = "my-test")] public class mytestcontroller : controller {      ... } 

this allowed me delete area route registration file too!


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -