Use Ajax and JsonResult in ASP.NET MVC 3

前端 未结 3 1983
野趣味
野趣味 2020-12-29 16:33

I need to get string array or list with ajax and Action, this is my Implementation:

This is my html Dom of view of Index action in AccessMenuController:



        
3条回答
  •  情深已故
    2020-12-29 17:05

    Move your $(document).ready function to your View like this:

    
    

    Then in your JS file add url parameter to your function and change ajax call:

    function RoleChangeHandler(pageUrl) {
    
        $.ajax({
            url: pageUrl,
            type: 'POST',
            data: { 'roleId': '61AD3FD9-C080-4BB1-8012-2A25309B0AAF' },
            dataType: 'json',
            processData: false,
            contentType: 'application/json; charset=utf-8',
            success: function (data) { SuccessRoleChangeHandler(data); },
            error: OnFailRoleChangeHandler
        });
        return false;
    }
    

    This should work as you expected.

提交回复
热议问题