进行Ajax调用并在ASP.NET MVC应用程序中返回布尔值

3 javascript ajax asp.net-mvc jquery

我想在ASP.NET MVC应用程序中进行ajax调用(使用JQuery)并返回一个布尔值,我该怎么做?

谢谢

Mis*_* N. 13

好吧,可能最好的解决方案是使用JSON序列化.

public ActionResult DoSomething(string parameter)
    {
        //do something with parameter
        bool result = true;
        return Json(new ActionInfo()
        {
            Success =result,     
        });
    }
Run Code Online (Sandbox Code Playgroud)

ActionInfo只是一个带有一个属性的简单类,boolean Success.Then,jquery ajax调用:

$.ajax({
type: "POST",
url: "YourController/DoSomething?parameter=pValue",
data: {},
dataType: "json",
success: function(actionInfo) {

    alert(actionInfo.Success);

}});
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.