Pravinkumar Birajdar

Pravinkumar Birajdar

  • 1.1k
  • 584
  • 109.4k

asp.net WebAPI showing error as [objec Object]

Jul 26 2020 7:02 AM
asp.net WebAPI showing error as [objec Object]
 
 web api
  1. public class BrandsController : ApiController  
  2.     {  
  3.         public List<Brand> Get()  
  4.         {  
  5.             EFDBFirstDatabaseEntities db = new Models.EFDBFirstDatabaseEntities();  
  6.             List<Brand> brands = db.Brands.ToList();  
  7.             return brands;  
  8.         }  
  9.     }  
in view:
  1. @{  
  2.     ViewBag.Title = "Index";  
  3.     Layout = "~/Views/Shared/_LayoutPage1.cshtml";  
  4. }  
  5.   
  6.   
  7. <div class="container">  
  8.     <h2>Brands</h2>  
  9.     <button type="button" id="btnGetBrands" class="btn">Get Brands</button>  
  10.     <table class="table brandsTable">  
  11.         <tr>  
  12.             <th>Brand ID</th>  
  13.             <th>Brand Name</th>  
  14.         </tr>  
  15.   
  16.     </table>  
  17.   
  18.     <script type="text/javascript">  
  19.         $("#btnGetBrands").click(() => {  
  20.             $.ajax({  
  21.                 type: "GET", url: "/api/Brands", success: (response) => {  
  22.                     for (var i = 0; i < response.length; i++) {  
  23.                         var br = response[i];  
  24.                         var str = "<tr><td>" + (i + 1) + "</td> <td>" + br.BrandName + "</td></tr>";  
  25.                         $(".brandsTable").append(str);  
  26.                     }  
  27.                 }, error: (err) => {  
  28.                     alert(err);  
  29.                     console.log(err);  
  30.                 }  
  31.             });  
  32.         });  
  33.   
  34.     </script>  
  35. </div>  
 Please help me...

Answers (5)