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 8150271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:01:15+00:00 2026-06-06T15:01:15+00:00

I am using mvc webapi to create a REST API and struggling to find

  • 0

I am using mvc webapi to create a REST API and struggling to find an example dealing with POSTs to nested resources.

Basically, I want to POST a comment to a blog post using a URL like:

~/posts/2/comments

I would also like to be able to send DELETE and PUTs to the following

~/posts/2/comments/5

What should my route registration look like, and what should my method signature on my PostsController look like?

Thanks!

  • 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-06-06T15:01:16+00:00Added an answer on June 6, 2026 at 3:01 pm

    For nested resources I would suggest that you create very specific routes for the controllers/actions that you want to access.

    routes.MapHttpRoute(
        name: "Posts Routes",
        routeTemplate: "api/posts/{postId}/comments/{commentID}",
        defaults: new { controller = "Posts", action="CommentsForPosts" }
    );
    
    public HttpResponseMessage CommentsForPosts(int postId, int commentID) {
        //go to work
    }
    

    There’s no convention in the framework for nested resources but routing gives you the flexibility to map your controllers, methods, and URIs however you see fit

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

Sidebar

Related Questions

I'm implementing a web API using the REST for ASP.NET MVC framework (MVC 2).
I am having problem using mvc:resources in spring 3.1 configuration. Initially i was working
I am using ASP.NET MVC 4 Beta with Web API - although I believe
I'm using ASP.NET MVC 3 to create a webapp that hosts business games. On
I'm creating an MVC website and also intend to create a web API for
I'm tasked to create a web application. I'm currently using c# & asp.net (mvc
I tried creating a small example using Spring, rest, Hibernate. In order to have
I'm trying to create a ASP.NET MVC 2 webapp using the Northwind database following
I'm developing webapp using spring 3 mvc and using annotation-based controllers. I want to
In my webapp, I am using Spring MVC as my controller layer. However, using

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.