Click here to Skip to main content
15,891,714 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi iam a beginner in asp.net mvc i need a help please  i want to get a table from database by using ajax

no action do
thats my code

What I have tried:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>GetData</title>

    <script src="~/Scripts/jquery-3.4.1.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

</head>
<body>

    <div>
        <input id="btn" type="button" value="LIST" />
        <script>

            $(document).ready(function () {
                $('#btn').click(function() {
                    $.ajax ({

                        url:'@Url.Action( "GetData","Home")',
                        type: "GET",
                        datatype: "json"
                    }


                    )}



                )}
                  )
        </script>




    </div>
</body>
</html>



my action code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using simpletestonajax.Models;
using System.Web.Script.Serialization;
namespace simpletestonajax.Controllers

{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public JsonResult GetData()
        {
            DKWASCKEntities1 db = new DKWASCKEntities1();
            db.Configuration.ProxyCreationEnabled = false;
            var dkw = db.Customers.list();
            
                      
            return Json(dkw, JsonRequestBehavior.AllowGet);


        }
    }
}
Posted
Comments
F-ES Sitecore 10-May-19 5:59am    
Loop through each result and create tr and td elements and add them to a table. Google "create table jquery" and you'll find lots of examples

https://stackoverflow.com/questions/17724017/using-jquery-to-build-table-rows-from-ajax-responsejson
ahmedbelal 10-May-19 7:14am    
Do you mean i should make a view list to customer or table before code ??
Kornfeld Eliyahu Peter 12-May-19 7:28am    
Do you mean that you do not reach the controller's code?
Or do you mean that you do not see the results after returning to the client from the controller?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900