根据键抛出错误从字典中获取值 - syncfusion schedule
Get value from dictionary based on key throws error - syncfusion schedule
在我使用 syncfusion 计划的 ASP.NET (c#) 应用程序中,我试图根据键从字典中获取值。
当我尝试这样做时,我收到此错误消息:
System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.
这行代码(我试图获取键 'Subject' 的值并将其分配给变量 sSubject
)抛出错误:
string sSubject = list["Subject"].ToString();
代码:
public Dictionary<string, object> Arguments { get; set; }
protected void Schedule1_ServerAppointmentEdited(object sender, Syncfusion.JavaScript.Web.ScheduleEventArgs e)
{
Arguments = e.Arguments["appointment"] as Dictionary<string, object>;
dynamic list = Arguments as Dictionary<string, object>;
string sSubject = list["Subject"].ToString();
}
如果我调试我的代码以查看字典中的内容,我确实看到存在键 'Subject':
我做错了什么?如何从键 'subject' 中获取值 'test subject'?
项目:http://www.syncfusion.com/downloads/support/forum/119417/ze/ScheduleCRUDWithWebServices-728709208
谢谢
您的字典在列表中,即第二个元素。您应该按如下方式访问它:
string sSubject = list[1]["Subject"].ToString();
这就是我最终检索到键值 'subject' 的方式:
Arguments = e.Arguments["appointment"] as Dictionary<string, object>;
//dynamic list = Arguments as Dictionary<string, object>;
System.Collections.ArrayList list2 = (System.Collections.ArrayList)Arguments["changed"];
Dictionary<string, object> dic = (Dictionary<string,object>)list2[0];
string sSubject2 = dic["Subject"].ToString();
通常,服务器端参数在执行编辑操作时只会收到约会详细信息。您能否分享关于哪个特定场景的详细信息,您将获得带有“添加”和“更改”选项的参数,如您的屏幕截图所示。
此致,
陀罗尼
在我使用 syncfusion 计划的 ASP.NET (c#) 应用程序中,我试图根据键从字典中获取值。
当我尝试这样做时,我收到此错误消息:
System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.
这行代码(我试图获取键 'Subject' 的值并将其分配给变量 sSubject
)抛出错误:
string sSubject = list["Subject"].ToString();
代码:
public Dictionary<string, object> Arguments { get; set; }
protected void Schedule1_ServerAppointmentEdited(object sender, Syncfusion.JavaScript.Web.ScheduleEventArgs e)
{
Arguments = e.Arguments["appointment"] as Dictionary<string, object>;
dynamic list = Arguments as Dictionary<string, object>;
string sSubject = list["Subject"].ToString();
}
如果我调试我的代码以查看字典中的内容,我确实看到存在键 'Subject':
我做错了什么?如何从键 'subject' 中获取值 'test subject'?
项目:http://www.syncfusion.com/downloads/support/forum/119417/ze/ScheduleCRUDWithWebServices-728709208
谢谢
您的字典在列表中,即第二个元素。您应该按如下方式访问它:
string sSubject = list[1]["Subject"].ToString();
这就是我最终检索到键值 'subject' 的方式:
Arguments = e.Arguments["appointment"] as Dictionary<string, object>;
//dynamic list = Arguments as Dictionary<string, object>;
System.Collections.ArrayList list2 = (System.Collections.ArrayList)Arguments["changed"];
Dictionary<string, object> dic = (Dictionary<string,object>)list2[0];
string sSubject2 = dic["Subject"].ToString();
通常,服务器端参数在执行编辑操作时只会收到约会详细信息。您能否分享关于哪个特定场景的详细信息,您将获得带有“添加”和“更改”选项的参数,如您的屏幕截图所示。
此致,
陀罗尼