Click here to Skip to main content
14,238,047 members
Rate this:
Please Sign up or sign in to 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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100