how to get the result from controller in ajax json

冷暖自知 提交于 2019-12-13 03:56:34

问题


Isend the some aruguments to controller using ajax but it does not return the value.

My concept : selected @html.dropdownlist value i send to the controller , using this value thats perfrom the get the valus for bind the property to another dropdownlist using mvc3

IGot this answer : verfif given link

verfif given link


回答1:


you are passing type option in ajax twice and the url is not formatted properly

function onChange(bookid) { 
          $.ajax({
            type: "GET",
            url: '@Url.Action("books","subject")',
            data : { bookid: bookid},
            dataType: "json",
            success: function (result) { 
              alert('success');
              //do whatever you want
            },
            error: function(result){
            }
        }); 
    };

You are passing dataType as json. So, if you want to hit the success result for $.ajax, you need to return Json from your action result instead of returning as View.

When you return as View it gives error always.

    public ActionResult books(string bookid)
    {

        var books= service.books(projectId); 

        // books are stored in list format
        return Json(books);
    }

Hope it helps you.



来源:https://stackoverflow.com/questions/14744753/how-to-get-the-result-from-controller-in-ajax-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!