7

このコードがあると、警告が表示されます:Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

    public async Task<ActionResult> Details(Guid id)
    {
        var calendarEvent = await service.FindByIdAsync(id);
        if (calendarEvent == null) return RedirectToAction<CalendarController>(c => c.Index());
        var model = new CalendarEventPresentation(calendarEvent);
        ViewData.Model = model;
        return View();
    }

    public async Task<RedirectResult> Create(CalendarEventBindingModel binding)
    {
        var model = service.Create(binding);
        await context.SaveChangesAsync();
        return this.RedirectToAction<CalendarController>(c => c.Details(model.CalendarEventID));
    }

await演算子を追加すると、次のようになります。

Error CS4034 The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.

asyncこのような修飾子を追加すると:

return this.RedirectToAction<CalendarController>(async c => await c.Details(model.CalendarEventID));

エラーはError CS1989 Async lambda expressions cannot be converted to expression trees

では、非同期コントローラーで強く型付けされた RedirectToAction (MVC Futures を使用しています) を使用するにはどうすればよいでしょうか?

4

1 に答える 1