hi iam a beginner in asp.net mvc i need a help please i want to get a table from database by using ajax
@{ 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>
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); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)