Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 601271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:41:48+00:00 2026-05-13T16:41:48+00:00

Before I ask my question: I just started ASP.NET MVC, so an advanced answer

  • 0

Before I ask my question: I just started ASP.NET MVC, so an advanced answer will maybe hard to understand 😉

I’m having 3 tables (I’ll add just a few of the fields below)

  • Shops (ShopID, Name)
  • Products (ProductID, Name, ShopID)
  • Comments (CommentID, ProductID, UserID, CommentText)

Now what I want to do is this:

http://www.site.com/Shops

//Gives me a list of shops

http://www.site.com/Shops/ShopName

//Gives me some details about the shop called ShopName and lists all the products that the shop has

http://www.site.com/Shops/ShopName/ProductName/

//Gives me all the comments of that product called ProductName from that specific shop called ShopName

http://www.site.com/Shops/ShopName/ProductName/ASpecificCommentHere

//Gives me a specific comment on that product of that shop

and other things like

http://www.site.com/Shops/ShopName/ProductName/AddComment

//Adds a new comment to that product from that shop

Now I only have a ShopsController which makes it possible for me to do something like this now:

http://www.site.com/Shops/

// Gives me a list of all shops

and

http://www.site.com/Shops/Details/123

// Gives me some details about the shop with ID 123 and should list its products.

But here is also the first problem: I don’t want the ID number in the url like /Shops/123 but rather the name like /Shops/ShopName and I don’t know if it’s good to have /Details/ there in the url. Maybe /Shops/ShopName would be better without the Details part in between?

How should I do this?
Should I create also a Controller for my Products and for my Comments that I have 3 controllers in total?
Or should I just keep one ShopController to always get the first part of the url (so that it always starts with) site.com/Shops/ShopName/…

Thanks in advance

(and a short little question, should ViewModels be placed in the controllers directory?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:41:48+00:00Added an answer on May 13, 2026 at 4:41 pm

    Kind a doing your work, but – whatever.
    I would go with something like this (be warned – it’s untested)…

    As you already likely know – order is important.

    http://www.site.com/Shops/ShopName/ProductName/AddComment =>

    routes.MapRoute(
        "Product",
        "Shops/{shopName}/{productName}/{action}",
        new { controller="comment"}
    );
    

    http://www.site.com/Shops/ShopName/ProductName/ASpecificCommentHere =>

    routes.MapRoute(
        "Product",
        "Shops/{shopName}/{productName}/{commentName}",
        new { controller="comment", action="details"}
    );
    

    http://www.site.com/Shops/ShopName/ProductName/AddProduct =>

    routes.MapRoute(
        "Product",
        "Shops/{shopName}/{productName}/{action}",
        new { controller="product"}
    );
    

    http://www.site.com/Shops/ShopName/ProductName/ =>

    routes.MapRoute(
        "Product",
        "Shops/{shopName}/{productName}",
        new { controller="product", action = "details"}
    );
    

    http://www.site.com/Shops/ShopName =>

    routes.MapRoute(
        "ShopDetails",
        "Shops/{shopName}",
        new { controller="shop", action = "details"}
    );
    

    http://www.site.com/Shops (NB: this route is ‘global’, for every controller) =>

    routes.MapRoute(
        "List",
        "{controller}",
        new { action = "list"}
    );
    

    Maybe this can be optimized or worse – it’s wrong but it should give you some better understanding for sure.

    Remember not to name shops/controllers/comments as according controller actions. That’s an issue with this routing approach.

    And i hope you noticed that i would create 3 different controllers (what might and might not be a good decision – that’s based on expectable weight and complexity of controller logic).

    Another tip – read about model binding. Using custom binders you could replace string parameters (entity names) with actual, already assembled objects. Maybe that wouldn’t be worth for this particular case, but model binding surely is 2nd important and hardest thing to grasp when facing asp.net mvc.

    And i lied, i wouldn’t go with this because i prefer specifying controller specific routes using attributes directly on actions (omitted that because it seems more advanced).

    Routing is like regular expressions. There’s a moment when it just ‘clicks’ and seems natural and easy.


    Already answered second question as comment to your question. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is maybe a stupid question, but I figured I'd ask before I did
Before I ask my question, let me just say that I know very little
Before I ask the question let me just clarify that the objective of this
Before I ask my question, I want to mention that I am only today
Before I ask the question let me state that I have attempted to google
Before I ask this question I would to apologise because of the fact that
I tried to ask this question before but I guess I didnt explain myself
I don't know if this question has been ask before. But I have a
Before you guys ask, yes I've searched online for the answer, but everything I
I have tried to ask a variant of this question before. I got some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.