Par*_*yam 6 message asp.net-core
显示简单消息的解决方法是什么?如果我只想在网页中显示变量的值,请告诉我类似于 Response 的内容。写。
Response.Write使用System.Web命名空间,并且它在 Asp.NET Framework 中使用,而不是在 Asp.NET Core 中使用。
如果我只想在网页中显示变量的值,请告诉我类似于 Response 的内容。写。
告诉我如何在 cshtml 文件中显示简单的消息
目前尚不清楚该变量来自哪里或您想在哪里使用Response.Write.
如果你想将数据从控制器传递到视图,你可以使用ViewBag/ViewData
行动:
public IActionResult Index()
{
ViewBag.Title = "hello";
return View();
}
Run Code Online (Sandbox Code Playgroud)
看法:
@ViewBag.Title
Run Code Online (Sandbox Code Playgroud)
如果您只想在视图中显示一条消息,您可以使用HttpContext.Response.Body.Write
public async Task Index()
{
var str = "hello world";
byte[] bytes = Encoding.ASCII.GetBytes(str);
await HttpContext.Response.Body.WriteAsync(bytes);
}
Run Code Online (Sandbox Code Playgroud)
请参阅Asp.Net Core 2 中是否有相当于“HttpContext.Response.Write”的内容?
| 归档时间: |
|
| 查看次数: |
8905 次 |
| 最近记录: |