[英]What c# classes and functions can be used in razor?
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. 此外,您可以使用@DateTime.Now
来获取当前时间。 My question is: what functions can be used? 我的问题是:可以使用哪些功能? From where Razor import them? Razor从哪里导入它们?
Any public class. 任何公共课。 They get imported with @using MyNamespace
. 它们使用@using MyNamespace
导入。 You can also import them in the config file 您也可以在配置文件中导入它们
<system.web.webPages.razor>
element. 元件。
You can use anything you want. 你可以使用你想要的任何东西。 It's no different from code in a .cs file. 它与.cs文件中的代码没有什么不同。 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. 如果您需要在另一个尚未添加到web.config中的命名空间中使用某些内容,则可以像在.cs文件中一样添加using语句。
@using System.Collections.Generic;
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. 如果您希望@中的代码不被视为代码,请将其包装在<text></text>
块中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.