Introduction
This is a simple example which send an ajax request to the ActionResult and return a JsonResult.
jQuery script for sending the request
jQuery(document).ready(function(){
$("#YourDropDownId").change(function() {
var ServiceUrl ="/YourController/Action?id=" + 1;
var content = '';
$.support.cors = true;
$.ajax({
type: 'GET',
url: ServiceUrl,
async: true,
cache: false,
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: 'json',
error: function (xhr, err) {
},
success: function (result, status) {
$('#yourTextId').val(result.Value);
}
});
});
});
ActionResult
[HttpGet]
public ActionResult Action(int id)
{
var result = new { Value = "my Json result" };
return Json(result, JsonRequestBehavior.AllowGet);
}
Enjoy Coding…