$(document).ready(function(){ //wrap under document.ready
$(".UserSelected").change(function () { //put '.' here instead of '#' because its a class selector
alert("dropdown value = " + $(this).val());
});
});
Edit:-
As questioner put another question in comments section so i m answering it here.
In order to call a action from jquery you can make a ajax call as :
View :-
$(document).ready(function(){
$(".UserSelected").change(function () {
var serviceURL = '/AjaxTest/FirstAjax'; //here 'AjaxTest' is controller name and 'FirstAjax' is action name or you can also use @Url.Action() to specify url here
$.ajax({
type: "GET",
url: serviceURL,
data:{ param = $(this).val() },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
alert(data);
}
function errorFunc() {
alert('error');
}
});
});
Controller :
public class AjaxTestController : Controller
{
//
// GET: /AjaxTest/
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult FirstAjax(string param)
{
return Json("test", JsonRequestBehavior.AllowGet);
}
}