jquery - 从 ASP.NET MVC ActionResult 返回 bool

标签 jquery asp.net-mvc

我通过 jquery 提交了表单,但我需要 ActionResult 返回 true 或 false。

这是 Controller 方法的代码:

    [HttpPost]
    public ActionResult SetSchedule(FormCollection collection)
    {
        try
        {
            // TODO: Add update logic here

            return true; //cannot convert bool to actionresult
        }
        catch
        {
            return false; //cannot convert bool to actionresult
        }
    }

我将如何设计 JQuery 调用来传递表单数据并检查返回值是 true 还是 false。如何编辑上面的代码以返回 true 或 false?

最佳答案

您可以以 bool 形式或 bool 属性返回 json 结果。像这样的事情:

[HttpPost]
public ActionResult SetSchedule(FormCollection collection)
{
    try
    {
        // TODO: Add update logic here

        return Json(true);
    }
    catch
    {
        return Json(false);
    }
}

关于jquery - 从 ASP.NET MVC ActionResult 返回 bool,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2374879/

相关文章:

jquery - 刷卡盒 : Stop control bars from hiding

asp.net-mvc - AzureReader2 与 ImageResizer 前缀问题

c# - 返回类型为 IEnumerable 而不仅仅是 List?

asp.net - Windows 身份验证在 IISExpress 中有效,但在 IIS 中无效

JavaScript 平滑滚动 - iPhone

jquery - 如何将点击函数放入回调函数中?

jquery - <select> onchange 与 jQuery 1.3.2 和 IE7

javascript - YouTube 滚动显示

asp.net-mvc - ASP.NET MVC 3 下拉列表

c# - 无人值守的 DropBox .net 后端访问