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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:27:30+00:00 2026-06-17T03:27:30+00:00

I tried to make ASP.NET Web Api CRUD operation in VS 2010 web application,

  • 0

I tried to make ASP.NET Web Api CRUD operation in VS 2010 web application, but why the result is not returning all entire row from source table.

This is my code :

Route/Globax.asax

protected void Application_Start(object sender, EventArgs e)
        {
            RouteTable.Routes.MapHttpRoute(
            name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}", // browse with localhost:7031/api/product
                //routeTemplate: "{controller}/{id}",  // browse with localhost:7031/product
                 defaults: new { id = System.Web.Http.RouteParameter.Optional }
      );

Controller/ProductController.cs :

    public class ProductController : ApiController
    {
        NorthwindEntities db = new NorthwindEntities();

        public List<Product> GetAll()
        {
            return db.Products.ToList<Product>();// ;
        }

View/ViewProduct.aspx :

    <script src="Script/jquery-1.7.1.min.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $('#<%= cviewproduct.ClientID %>').click(function (e) {
            getProducts();
            e.preventDefault();
        });

    });

    function getProducts() {
        $.getJSON("/api/product",
                function (data) {
                    $.each(data, function (key, val) {
                        //var str = val.ProductName;
                        // alert(str);

                        var row = '<tr> <td>' + val.ProductName + '</td><td>' + val.ProductID + '</td><tr/>';

                        $(row).appendTo($('#tblproduct'));


                    });
                });
    }
</script>

Bellow Is The Result of product Controller via ‘http://localhost:7031/api/product‘ :

enter image description here

Bellow Is The Result of getProducts() function :

enter image description here

Please help me.

Any idea or suggestion ?

  • 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-17T03:27:31+00:00Added an answer on June 17, 2026 at 3:27 am

    When you execute $.getJSON("/api/product", ..., you are not getting back XML as you posted. You are getting back JSON.

    As a first step, I suggest you download and install Fiddler2. Open it, and use the Composer tab to execute a GET for http://localhost:7031/api/product. That should show you the JSON returned, which will be different from the XML. Post that JSON to your original question and we should be able to help further.

    My guess is that the JSON is not properly formatted. What does your WebApiConfig.cs class look like?

    Update

    Yes, there is a better way. First, create an ApiModel (ApiModel is to WebAPI what ViewModel is to MVC):

    public class ProductApiModel
    {
        public int ProductId { get; set; }
        public string ProductName { get; set; }
    }
    

    Now, return this instead of an entity from your controller:

    public class ProductController : ApiController
    {
        public IEnumerable<ProductApiModel> GetAll()
        {
            var products = db.Products
                .OrderBy(x => x.ProductID)
                .Select(x => new ProductApiModel
                {
                    ProductId = x.ProductID,
                    ProductName = x.ProductName
                });
            return products;
        }
    }
    

    If you used AutoMapper, you could make your controller code a bit shorter:

    public class ProductController : ApiController
    {
        public IEnumerable<ProductApiModel> GetAll()
        {
            var entities = db.Products.OrderBy(x => x.ProductID);
            var models = Mapper.Map<ProductApiModel[]>(entities);
            return models;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asp.net web service application created in VS 2010. I created this web
I am using Asp.net MVC 4 Web Api project. MY application uses mvc to
I am trying to make a simple web application using ASP.NET and Interop COM.
What is the simplest way to distribute an asp.net web application? I tried to
I tried to make a click counter in MySQL, but it dose not seem
I am using web api with ASP.NET MVC 4. I have the following named
I have some ASP.NET web services which all share a common helper class they
When developing an ASP.NET web application that is targeted at mobile devices (mainly tablets),
I'd like to trap any unhandled exception thrown in an ASP.NET web service, but
I have an ASP.NET MVC 3 (.NET 4) web application. This app fetches data

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.