You must Sign In to post a response.
  • Category: ASP.Net MVC

    Crud operations using ajax call in mvc4


    I am new to MVC , I want to perform crud operations(insert,update,delete) in mvc4 using the ajax call.
    Can any one provide me good example which includes all those for better understanding.
    And please describe the control flows between request and response ,,
    what is type: "PUT", type:'GET" ,
    how to use it,
    please provide the syntax and explain all those things that is require for ajax call and crud operation.
  • #766771

    you can try this code for load data using json

    $(document).ready(function () {

    function LoadDatas() {
    url: '/home/GetContacts',
    type: 'GET',
    dataType: 'json',
    success: function (d) {
    if (d.length > 0) {
    var $data = $('<table></table>').addClass('table table-responsive table-striped');
    var header = "<thead><tr><th>Contact Person</th><th>Contact No</th></tr></thead>";
    $.each(d, function (i, row) {
    var $row = $('<tr/>');
    error: function () {
    alert('Error! Please try again.');

    Controller Code

    public JsonResult GetContacts()
    List<Contact> all = null;

    using (MyDBEntities dc = new MyDBEntities())
    var contacts = (from a in dc.Contacts

    select new
    if (contacts != null)
    all = new List<Contact>();
    foreach (var i in contacts)
    Contact con=new Contact();
    con.ContactPerson ="AA";
    con.ContactNo = "123456";

    return new JsonResult { Data = all, JsonRequestBehavior = JsonRequestBehavior.AllowGet };

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • Sign In to post your comments