/// <summary> /// 把ModelState错误 添加到 BadRequestObjectResult对象里 /// </summary> /// <param name="controller"></param> /// <param name="key">错误Key</param> /// <param name="error">错误信息</param> /// <returns>BadRequestObjectResult</returns> public static BadRequestObjectResult ModelStateError(this ControllerBase controller, string key, string error) { controller.AddStateError(key, error); return controller.BadRequest(controller.ModelState); }