這取決於您的需求。你想創建一個包含你的響應狀態的泛型類?在這種情況下,您可以創建一個通用的類。
public class Response
{
/// <summary>
/// Gets or sets a value indicating whether this instance is success.
/// </summary>
/// <value>
/// <c>true</c> if this instance is success; otherwise, <c>false</c>.
/// </value>
public bool IsSuccess { get; set; }
/// <summary>
/// Gets or sets the error message.
/// </summary>
/// <value>
/// The error message.
/// </value>
public string ErrorMessage { get; set; }
}
之後,你可以使用這樣的:
return Ok<Response>(new Response { ErrorMessage = "", IsSuccess = true });
或者你也可以只使用OK響應不帶任何參數,並檢查請求的狀態代碼對你的角度應用:
return Ok();
角部位:
$http({
method: 'GET',
url: '/someUrl'
})}).then(function successCallback(response) {
//If it's Ok -> 200 HTTP
}, function errorCallback(response) {
//If error occured -> 500 HTTP etc.
});
爲什麼不只是返回一個空的行程足以滿足成功?如果不成功,您可以返回其他代碼。 –
你的意思是空的確定嗎?問題是我需要檢查角度的響應 – mbrc
只是'返回OK()' –