主要问题
我在 Microsoft Bot Framework 中使用自适应卡片。我遇到了一个问题,在用户选择他想要的日期后,我不知道如何从 DateInput 获取值。以下是我目前的代码:
public async Task StartAsync(IDialogContext context)
{
string pIdentifier = serviceFactory.ProfileService.GetPatientIdentifier(nric);
string response = serviceFactory.DentalAppointmentService.GetSlotSearchDates(nric,apptId,caseNumber, institutionCode, pIdentifier);
string[] split = response.Split(' ');
DateTime earliestStartDate = DateTime.ParseExact(split[0], "yyyy'-'MM'-'dd'T'HH':'mm':'ss", CultureInfo.InvariantCulture);
DateTime latestEndDate = DateTime.ParseExact(split[1], "yyyy'-'MM'-'dd'T'HH':'mm':'ss", CultureInfo.InvariantCulture);
await context.PostAsync("Your appointment can only be rescheduled within this period " + earliestStartDate.ToShortDateString() + " to " + latestEndDate.ToShortDateString());
AdaptiveCard card = new AdaptiveCard();
card.Body.Add(new TextBlock()
{
Text = "Enter new Date",
Size = TextSize.Large,
Weight = TextWeight.Bolder
});
DateInput input = new DateInput()
{
Id = "Date",
Placeholder = "New Date"
};
card.Body.Add(input);
card.Actions.Add(new SubmitAction()
{
Title = "Submit"
});
Attachment cardAttachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card
};
var message = context.MakeMessage();
message.Attachments = new List<Attachment>();
message.Attachments.Add(cardAttachment);
await context.PostAsync(message);
context.Wait(this.MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var temp = await result as Activity;
string date = temp.Text;
//DateTime newDate = DateTime.ParseExact(value.ToString(), "yyyy'-'MM'-'dd'T'HH':'mm':'ss", CultureInfo.InvariantCulture);
Debug.WriteLine("Entered Msg received Async:" + date);
await context.PostAsync(date);
}
引发的当前错误
我目前遇到了这个问题,我无法找到解决方案:
抛出异常:mscorlib.dll 中的“Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”