gpt4 book ai didi

kendo-ui - Kendo UI - 如何在 WEB API 上实现错误处理,非 MVC 使用 Kendo Grid

转载 作者:行者123 更新时间:2023-12-04 05:24:10 26 4
gpt4 key购买 nike

我的场景是我创建了一个返回 Active Directory 对象的 Web API。

我有这个 WEB API 函数创建 Active Directory 用户并创建一个返回 Active Directory 对象的用户,该对象包含 First Name , Last Name, Email, UserName, Etc. .. 如果出现错误,我将如何处理?

我正在使用 Kendo Grid 内联编辑 http://demos.kendoui.com/web/grid/editing-inline.html
我想将错误消息显示为弹出窗口

我该怎么做???

选项

  • try catch 错误并将 Active Directory 对象作为
    异常(exception)???
  • 我怎样才能捕捉到这是 Kendo UI?
  • 抛出响应并获取错误消息并在 Kendo Grid 中显示

    //HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.OK)
    //{
    //Content = new StringContent(string.Format("No User with ID = {0}.{1}", businessObject.UserName, ex.InnerException.ToString() )),
    //ReasonPhrase = "数据库中未找到客户 ID!"
    //};
    //抛出新的HttpResponseException(msg);

  • 或者
      //var message = string.Format("Error Message: {0}", taskCreateADUser.ADExceptionDescription);
    //throw new HttpResponseException(
    // Request.CreateErrorResponse(HttpStatusCode.OK, message));

    谢谢,
    马克莱文

    最佳答案

    每当 KendoUI 通过 Ajax 绑定(bind)时,它依赖于在 json 响应中发送的 ModelState 的序列化版本。本质上,如果 ModelState 无效,则返回到小部件(在本例中为网格)的 json 响应将包含如下内容:

    {
    "Errors":{
    "PropA":{
    "errors":[
    "Error1",
    "Error2"
    ]
    },
    "PropB":{
    "errors":[
    "FUBAR"
    ]
    }
    }
    }

    本质上,如果您希望网格对其进行响应,您的 WebAPI 将需要返回类似的数据结构。

    关于kendo-ui - Kendo UI - 如何在 WEB API 上实现错误处理,非 MVC 使用 Kendo Grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13394510/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com