什么c#类和函数可以在剃须刀中使用?

时间:2021-11-07 18:06:05

Using ASP.NET MVC can be used the view engine Razor.

使用ASP.NET MVC可以使用视图引擎Razor。

Razor let you use c# code after the @ sign.

Razor让你在@符号后面使用c#代码。

As example

@if (Model.Category == "watersports")
{
    <p>Splash!!</p>
}

Furthermore you can use something like @DateTime.Now for get the current time. My question is: what functions can be used? From where Razor import them?

此外,您可以使用@ DateTime.Now之类的内容来获取当前时间。我的问题是:可以使用哪些功能? Razor从哪里导入它们?

3 个解决方案

#1


7  

Any public class. They get imported with @using MyNamespace. You can also import them in the config file

任何公共课。它们使用@using MyNamespace导入。您也可以在配置文件中导入它们

<system.web.webPages.razor>

element.

#2


3  

You can use anything you want. It's no different from code in a .cs file. If you need to use something in another namespace that hasn't been added to your web.config already, you can add using statements just as you would in a .cs file.

你可以使用你想要的任何东西。它与.cs文件中的代码没有什么不同。如果您需要在另一个尚未添加到web.config中的命名空间中使用某些内容,则可以像在.cs文件中一样添加using语句。

@using System.Collections.Generic;

#3


1  

You can use anything. Basically anything after @ is like writing in the code-behind. If you want code within your @ to not be seen as code, wrap it in a <text></text> block.

你可以使用任何东西。基本上@之后的任何东西都像是在代码隐藏中写作。如果您希望@中的​​代码不被视为代码,请将其包装在 块中。

#1


7  

Any public class. They get imported with @using MyNamespace. You can also import them in the config file

任何公共课。它们使用@using MyNamespace导入。您也可以在配置文件中导入它们

<system.web.webPages.razor>

element.

#2


3  

You can use anything you want. It's no different from code in a .cs file. If you need to use something in another namespace that hasn't been added to your web.config already, you can add using statements just as you would in a .cs file.

你可以使用你想要的任何东西。它与.cs文件中的代码没有什么不同。如果您需要在另一个尚未添加到web.config中的命名空间中使用某些内容,则可以像在.cs文件中一样添加using语句。

@using System.Collections.Generic;

#3


1  

You can use anything. Basically anything after @ is like writing in the code-behind. If you want code within your @ to not be seen as code, wrap it in a <text></text> block.

你可以使用任何东西。基本上@之后的任何东西都像是在代码隐藏中写作。如果您希望@中的​​代码不被视为代码,请将其包装在 块中。