ASP.NET routing with optional URL segments -


I am working on an ASP.NET MVC task list and want to get fancy with URL routing when I filter Are the list I have a verb method defined like this:

  public action list (int category eng, bull display, Tasef filter filter); Enum TaskFilter {MyTasks, MyDepartmentTasks, AllTasks}  

I want my URLs to look like this:

  / work / category 4 / my task / showpoints / / Tasks / Category 4 / My department / Tasks / Category 4 /  

Class # Segment will always be present. I MyTasks | MyDepartment | AllTasks Segment wants to be optional, if <<> is absent then the default for AllTasks . I also liked ShowCompleted to be optional, defaults to the default.

Is this kind of routing possible, or should I have to come back and use only query string parameters?

Follow-up / Additional Credit Questions: If I want the fourth parameter to filter by function method which is today. Day2Through10 (default looks like today) if absent)

Your case involves a little change with:

  Routes. MapRoute ("T1", "Work / category {classID}", new {controller = "task", action = "list", showcompleted = false, strfilter = taskfilter.AllTasks.ToString ()}); Routes MapRoute ("T2", "Work / category {classID} / {strFilter} /", new {controller = "task", action = "list", showCompleted = false}); For routes. Margaret ("T3", "Work / category {class id} / {strFilter} / display", new {controller = "task", verb = "list", showCompleted = true});  

You will need to change the list method to start as follows:

  public action list (int category ID, display, string struffler) {TaskFilterFilter = (Taskfilter) Enum.Parse (TYP (Taskfilter), String Filter);  

For your second query, you only need to use {Day2} and thus ActionResult must be passed. You should be able to understand this about what I have given you.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -