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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:57:55+00:00 2026-06-07T20:57:55+00:00

I have an entity on the server called foo which has a list of

  • 0

I have an entity on the server called foo which has a list of bars assigned to it. I want to be able to remove a single bar from the foo.

I don’t however want to update client side and send down the entire foo because the foo is a big object so would be a lot of Json to send up every time if I’m just removing one bar from the foo.

I just want to send down the bar then remove it from the foo entity.

I have my class foo

public class Foo
{
    public Foo()
    {
        Bars = new Collection<Bar>();    
    }

    public ICollection<Bar> Bars { get; set; }
}

I’ve mapped the route

routes.MapHttpRoute(
    name: "fooBarRoute",
    routeTemplate: "api/foo/{fooId}/bar/{barId}",
    defaults: new { controller = "Bar", action = "RemoveBarFromFoo" }
    );

Sending down the request via javascript (coffeescript)

$.ajax(
url: api/foo/1/bar/1,
data: jsonData,
cache: false,
type: 'XXX',
....

I’m just not sure what route to use, I’ve tried PUT but it doesn’t like it and I’m probably doing it wrong. I’m not really sure what route I should be using in this situation.

public class BarController : ApiController
{
    public void RemoveBarFromFoo(int fooId, Bar bar)
    {    
        // get the foo from the db and then remove the bar from the list and save
    }
}

My question: What route should I be using to achieve this goal? Or if I’m going about this the wrong way what should I be doing?

Thanks, Neil

  • 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-07T20:57:57+00:00Added an answer on June 7, 2026 at 8:57 pm

    The HTTP verb that you are using must be DELETE and the action name called Delete in order to follow standard RESTful conventions. Also this action should not take a Bar object as parameter. Only the barId because that’s all that the client sends:

    public class BarController : ApiController
    {
        public void Delete(int fooId, int barId)
        {    
            // get the foo from the db and then remove the bar from the list and save
        }
    }
    

    and you call:

    $.ajax({
        url: 'api/foo/1/bar/1',
        type: 'DELETE',
        success: function(result) {
    
        }
    });
    

    and now yuo could remove the action from your route definition because it is the HTTP verb that dictates which action should be invoked:

    routes.MapHttpRoute(
        name: "fooBarRoute",
        routeTemplate: "api/foo/{fooId}/bar/{barId}",
        defaults: new { controller = "Bar" }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an entity called PendingPartners which has a navigation property to the Residents
I have an entity called Requests which has a navigation called StatusHistories I need
I have Entity Framework entities Events which have an EntityCollection of RSVP. I want
I have a ListView which I filled in from SQL Server view called view_ListaKlientow
Let's say you have a server-side entity called MyEntity and you also have all
I have an entity (on Core Data ) called Contact , each contact has
I have an Entity Data Model-based app that uses SQL Server CE 3.5 as
We have a project that uses JPA/Hibernate on the server side, the mapped entity
I am using MVC (C#) and the Entity Framework. I have a sql server
I have entity Recipes and it has a HasMany collection comments. In a MVC

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.