Click Here For MCQ

Monday, June 15, 2020

Ajax Actionlink using in ASP.net MVC C# Coding

Controller 


you must remember namespace in your controller

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;


public JsonResult Country()
        {

            var json = Mydata();
            return Json(json,JsonRequestBehavior.AllowGet);
        }

        private List<string> Mydata()
        {
            return new List<string>()
            {
            
                "state -- India",
                "state -- Usa",
                "state -- sri lanka",
                "state -- pakistan",
                "state -- Nepal"

            };
        }

View 


@{
    ViewBag.Title = "list";
}
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/jquery-1.10.2.js"></script>
<h2>Country j</h2>

@Ajax.ActionLink("countrys", "Country", new AjaxOptions()
{
    HttpMethod = "GET",
    InsertionMode = InsertionMode.Replace,
    UpdateTargetId = "Divids",
    LoadingElementId = "load"
});
<div id="load" style="display:none">
    <img src="~/Images/abc.gif" hight="100" width="200" />
</div>
<div id="Divids">

</div>

 

No comments:

Post a Comment