简体   繁体   English

C# Razor Core 3.1/6 列表 CSHTML

[英]C# Razor Core 3.1/6 List CSHTML

Opening a code block within the CSHTML should allow for normal C# code to work.在 CSHTML 中打开代码块应该允许正常的 C# 代码工作。

Using VS2022 on my .Net Core Project (Razor) intellisense seems to pick up HTML elements when opening the angle brackets for the LIST collection type when it should be TYPES in C#.在我的.Net Core Project (Razor) intellisense 上使用 VS2022 在打开 LIST 集合类型的尖括号时似乎会拾取 HTML 元素,而 LIST 集合类型应该是 C# 中的 TYPES。

In another project where nothing seems to have been different in the project the LIST seems to be working there properly.在另一个项目中似乎没有什么不同的项目中,LIST 似乎在那里正常工作。

在此处输入图像描述

If you introduce a new variable, you need to wrap it into a code block:如果引入新变量,则需要将其包装到代码块中:

@{
     List<string> surveyAnswers = new List<string>();
     var text = "Hello World!";
}

Using these values within html is then possible without the brackets:然后可以在没有括号的情况下在 html 中使用这些值:

<div>@text</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM