zeeshan akram

zeeshan akram

  • 1.4k
  • 325
  • 18k

C# function return value but not display value in grid ajax

Mar 24 2020 6:40 AM
Hi, I want to show data in grid function is calling but not show in the grid. I debug the code I can see the id value when the cursor reaches the $.ajax then directly go to the end of brackets, I don't know what is a problem any expert can you tell where I am wrong.
 
 
C# Function
  1. public JsonResult GetProduct_Detail(int id)  
  2.    {  
  3.        var resultProdD = _IProducts.GetProductByID(id);  
  4.        return Json(resultProdD,JsonRequestBehavior.AllowGet);  
  5.    }  
 Master  Grid 
  1. <div class="row">  
  2.                        <div class="col-md-12">  
  3.                            <div class="panel widget">  
  4.                                <div class="panel-heading">  
  5.                                     
  6.                                </div>  
  7.                                <div class="panel-body-list  table-responsive">  
  8.                                    <table class="table table-striped table-hover no-head-border">  
  9.                                        <thead class="vd_bg-grey vd_white">  
  10.                                            <tr>  
  11.                                                <th>#</th>  
  12.                                                <th>Name</th>  
  13.                                                <th>Model</th>  
  14.                                                <th>Condition</th>  
  15.                                                <th>UnitPrice</th>  
  16.                                                <th>Mani Price</th>  
  17.                                                <th>Discount</th>  
  18.                                                <th>Weight</th>  
  19.                                                <th>Action</th>  
  20.                                            </tr>  
  21.                                        </thead>  
  22.                                        <tbody>  
  23.                                            @foreach (var item in Model)  
  24.                                            {  
  25.                                                <tr>  
  26.                                                    <td>@item.ProductID</td>  
  27.                                                  
  28.                                                    <td>@item.PName</td>  
  29.                                            
  30.                                                    <td>@item.Model</td>  
  31.   
  32.                                                    <td>@item.Condition</td>  
  33.                                       
  34.                                                    <td>@item.ManificturedPrice</td>  
  35.   
  36.                                                    <td>@item.Discount</td>  
  37.   
  38.                                                    <td>@item.UnitWeight</td>  
  39.                                        
  40.                                                    <td>@item.UnitInStock</td>  
  41.                                                     
  42.                                                    <td class="menu-action">  
  43.                                                     <a href="javascript:void(0);" class="btn menu-icon vd_bd-grey vd_grey" data-original-title="view" data-toggle="tooltip" data-placement="top" data-id="@item.ProductID"><i class="fa fa-eye"></i> </a>   
  44.                                                        <a href="~/Items/[email protected]" class=" anchorDetail btn menu-icon vd_bd-grey vd_grey" data-original-title="view" data-toggle="tooltip" data-placement="top" data-id=""><i class="fa fa-pencil"></i> </a>    
  45.                                                        <a href="javascript:void(0);" class="btn menu-icon vd_bd-grey vd_grey" data-original-title="view" data-toggle="tooltip" data-placement="top" data-id="@item.ProductID"><i class="fa fa-times"></i> </a>    
  46.                                                    </td>  
  47.                                                </tr>  
  48.                                            }  
  49.                                              
  50.                                        </tbody>  
  51.                                    </table>  
  52.                                </div>  
  53.                            </div>  
Jquery Function
 
  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. debugger;
  4. var baseUrl = (window.location).href; // You can also use document.URL
  5. var id = baseUrl.substring(baseUrl.lastIndexOf('=') + 1);
  6. list_ProductDetail(id); //id=6 value show
  7. });
  8. function list_ProductDetail(id) //id=6 value show 
  9. {
  10. $.ajax({ when curror reached this line then go end brakets
  11. url: "/Items/GetProduct_Detail",
  12. type: "GET",
  13. contentType: "application/json;charset=utf-8",
  14. dataType: "json",
  15. data: { id: id },
  16. success: function (result) {
  17. $('#PName').val(result.PName);
  18. $('#ManificturedPrice').val(result.ManificturedPrice);
  19. $('#UnitWeight').val(result.UnitWeight);
  20. $.each(result, function (key, item) {
  21. var html = '';
  22. html += '<tr>';
  23. html += '<td>' + item.ProductID + '</td';
  24. html += '<td>' + item.OS + '</td>';
  25. html += '<td>' + item.PrcessorType + '</td>';
  26. html += '<td>' + item.RAM + '</td>';
  27. html += '<td>' + item.ScreenSize + '</td>';
  28. html += '<td>' + item.TouchScreen + '</td>';
  29. html += '<td>' + item.BatteryLife + '</td>';
  30. html += '<td>' + item.Camera + '</td>';
  31. html += '<td>' + item.Model + '</td>';
  32. html += '<td>' + item.Condition + '</td>';
  33. html += '<td>' + item.Discount + '</td>';
  34. html += '<td><a class="menu-action rounded-btn btn menu-icon vd_bd-grey vd_grey" data-toggle="tooltip" href="#" onclick="return GetProductDetail(' + item.ProductID + ')"><i class="fa fa-pencil"></i></a> | <a href="#" onclick="Delete(' + item.ProductID + ')"><i class="fa fa-thrash"></i></a></td>';
  35. });
  36. $('.tbody').html(html);
  37. },
  38. error: function (errormessage) {
  39. alert(errormessage.responseText);
  40. },
  41. });
  42. }

Answers (1)