Wednesday, 30 August 2017

Call Action from javascipt or Jquery or Ajax in MVC3 Razor

In this tutorial I will show you that how can we call action from jquery or ajax in MVC3 razor.
Let “GetData” is action which I will call using Jquery.
Here I am using ajax to call this action without any post backs.
Here is Example of it.
var url = '@Url.Action("GetData")'; 
$.ajax({
url: url,
type: 'GET',
cache: false,
data: { value: strId},    // this is the parameter which you want to pass to action
success: function (result) {
$('#result).html(result);
}

});
Also it can be done using GetJson in Jquery
 $(function () {
                $.getJSON('@Url.Action("GetData")', { id: strId }, function (result) {
                    var List = $('#grid');
                    List.empty();
                    List.append(result.Data);
                });
            });
        });
Like this you can call any action using jquery as per your requirements.

No comments:

Post a Comment

React Hooks - custom Hook

  v CustomHook Ø React allows us to create our own hook which is known as custom hook. Example – 1 localStorage Demo Step-1 Create ...