본문 바로가기
ASP.NET MVC/ASP.NET MVC2

Jquery AJAX로 호출하고 List<T>형식 JSon 형식으로 수신

by Hwoarang757 2013. 12. 12.

Html.DropDownList 의 Change 이벤트 발생시 Jquery 로 Mvc Action 메서드 호출!!


$("#ddlCenterCD").change(function () {

var selectedValue = $("#ddlCenterCD").val();

$.ajax({

url: "<%= Url.Action("ReturnRoomCD","User") %>",

type : "POST",

data : { CenterCD : selectedValue } ,

error : function ( xhr ,ajaxOptions,thrownError ) {

alert(xhr.status);

alert(thrownError);

},

success : function (result) {

alert(result);

}

});

});


 

 

Controller 페이지의 JsonResult Action

 

public JsonResult ReturnRoomCD(string CenterCD)

{

return Json(SQLDataContext.sp_select_operation_codegroup_usecenter("ROOMCD0000", CenterCD).ToList(), JsonRequestBehavior.AllowGet);

}