亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將枚舉值添加到操作內的列表

將枚舉值添加到操作內的列表

C#
溫溫醬 2022-11-22 10:19:46
我有以下代碼,其中有一些我無法解決的錯誤。如果用戶有權訪問,我正在嘗試向 a 添加值List,然后返回該List.notificationsList當我嘗試歸還它時,紅線出現在下面。但我不確定我一開始是否做對了。public ActionResult GetUserNotificationOptions() {    List<NotificationOption> notificationsList = new List<NotificationOption>();    if(UserAccountHandler.GetIsAuthorised(_db, RestrictedArea.Audits))    {        notificationsList.Add(NotificationOption.NewAudits);    }    if (UserAccountHandler.GetIsAuthorised(_db, RestrictedArea.Overview))    {        notificationsList.Add(NotificationOption.SiginificentDeviationInScore);    }    if (UserAccountHandler.GetIsAuthorised(_db, RestrictedArea.Action))    {        notificationsList.Add(NotificationOption.OutstandingActions);    }    return notificationsList;}
查看完整描述

3 回答

?
三國紛爭

TA貢獻1804條經驗 獲得超7個贊

對我來說,這看起來像是類型不匹配。我的 C# 生銹了,但看起來你的方法聲明它返回一個ActionResult,但實際上返回一個List<NotificationOption>.

有兩種方法可以解決此問題:

  1. 聲明類以返回列表使用public class List<NotificationOption> GetUserNotificationOptions{}

或者

  1. ActionResult在返回之前將您的列表轉換為。


查看完整回答
反對 回復 2022-11-22
?
心有法竹

TA貢獻1866條經驗 獲得超5個贊

如果您想將結果返回給客戶端,您可以將JsonResult其用作一種可能的選擇。


public JsonResult GetUserNotificationOptions() {


    ...

    return Json(notificationsList);


}


查看完整回答
反對 回復 2022-11-22
?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

您應該將函數聲明為:

public List<NotificationOption> GetUserNotificationOptions() {

否則返回變量與聲明的返回類型不兼容。


查看完整回答
反對 回復 2022-11-22
  • 3 回答
  • 0 關注
  • 158 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號