ASP.NET MVC Routing vs Concrete Actions

I'm a little confused for what reasons you can achieve something. My website can display a stream of stories for the user, and the feed can be one of several categories. (for example, you can view the All Stories feed or the My Submissions feed).

Regarding routing processing, does it make sense:

1) Have an action (Main / Index) to process different parameters of the "storyCategory" using this routing:

[Route("~/"), Route("")] //Index will be default route for both SiteRoot and SiteRoot/Home
[Route("{storyCategory?}/{page?}")]
[Route("{storyCategory?}/Page/{page?}")]
public ActionResult Index(Story.Category storyCategory = Story.Category.None, int page = 1)

OR

2) have a specific action for each storyCategory instead of passing enum in as a parameter:

[Route("~/"), Route("")] //Index will be default route for both SiteRoot and SiteRoot/Home
public ActionResult Index(int page = 1) 
public ActionResult ReadLater(int page = 1) 
public ActionResult PlanToUse(int page = 1)
+4
source share
2 answers

, , , ...

, , , "ReadLater" ( ), , .

:

  • ;
  • URL- ( "index" );
  • ;
  • .

, , , , :

namespace Stories
{
    public class ControllersNames {
        public const string AllStories = "AllStories";
        public const string MySubmissions = "MySubmissions";
    }

    public class ActionsNames
    {
        #region AllStories
        public const string AllStories_ReadLater = "ReadLater";
        public const string AllStories_PlanToUse = "PlanToUse";
        #endregion

        #region MySubmissions
        public const string MySubmissions_ReadLater = "ReadLater";
        public const string MySubmissions_PlanToUse = "PlanToUse";
        //same action but with different paramaters below
        public const string MySubmissions_PlanToReUse = "PlanToUse"; 
        public const string MySubmissions_Store = "Store";
        #endregion
    }
}

- :

<a ... href="@Url.Action(
      ActionsNames.MySubmissions_PlanToUse,
      ControllersNames.MySubmissions,
      new { page = Model.MySubmissions.IDPage })">

...

+2

, /.

. .

+1

Source: https://habr.com/ru/post/1648542/


All Articles