在 Razor 视图中使用 await [英] Use of await in Razor views

查看:65
本文介绍了在 Razor 视图中使用 await的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以await Razor .cshtml 视图中的任务?

Is it possible to await on tasks in Razor .cshtml views?

默认情况下,它抱怨它只能在标有 async 的方法中使用,所以我想知道是否有隐藏的开关可以启用它?

By default it complains that it can only be used in methods marked with async so I'm wondering if maybe there is a hidden switch somewhere that enables it?

推荐答案

在 ASP.NET Core 2.1 中,您可以在 Razor 视图中使用 await.

In ASP.NET Core 2.1, you can use await in Razor views.

参见 https://docs.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-2.1

示例:

@await Html.PartialAsync("../Account/_LoginPartial.cshtml")

这篇关于在 Razor 视图中使用 await的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆