简体   繁体   English

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

[英]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.

相关问题 如何在 ASP.NET Blazor 中定义全局 C# 代码类,哪些函数可以从相关剃须刀页面的每个部分类中调用? - How can i define gloabal C# code classes in ASP.NET Blazor which functions can be called from each partial class of the related razor pages? C#创建被多个类使用的枚举的最佳方法是什么? - C# What is the best way to create an enum that is used by multiple classes? c#中类,函数,变量等的正确命名符号是什么? - What is the correct naming notation for classes, functions, variables etc in c#? 这个PHP加密代码中使用的函数的C#等价物是什么? - What are the C# equivalents of the functions used in this PHP encryption code? 可以使用C#中的部分类来修改功能 - Can partial classes in c# be used to modify functionality 在Razor文件中使用C#代码和函数 - Using C# Code and Functions in Razor File c#razor在外部文件中起作用 - c# razor functions in external file 函数或变量是否可以存储在命名空间而不是类中 - C# - Can functions or variables be stored inside namespaces instead of classes - C# C#函数和类帮助 - C# functions and classes help C#MVC4剃刀-可以使用DisplayNameFor获得其他模型的Display(Name =…)吗? - C# MVC4 Razor - can DisplayNameFor be used to get a Display(Name = …) of a different model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM