Using ASP.NET MVC can be used the view engine Razor.
Razor let you use c# code after the @
sign.
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?
Any public class. They get imported with @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. 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.
@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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.