c# - asp.net mvc routing with multiple optional parameters did not work -


i wrote attribute route route("home/{category?}/{subcategory?}/list") want match following examples /home/c1/s1/list, /home/c1/list, /home/list

but match first url, optional parameter did not work. how use routing rule matches above 3 examples?

public class homecontroller : controller {     public iactionresult index()     {         return view();     }      [route("home/{category?}/{subcategory?}/list")]     public iactionresult list(category? category = null, subcategory? subcategory = null)     {         return content(category.tostring() + "/" + subcategory.tostring());     }      [route("home/{code}/detail")]     public iactionresult detail(string code)     {         return content(code);     } }   public enum category {     c1,     c2,     c3,     c4 }  public enum subcategory {     s1,     s2,     s3,     s4 } 

similar questions

routing optional parameters in asp.net mvc 5

mvc routing 1 fixed action , controllers multiple optional parameters

if route not work, can done using 3 routing rules.

[route("home/list")] [route("home/{category}/list")] [route("home/{category}/{subcategory}/list")] 

thx all.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo