What C # classes and features can I use with a razor?

Using ASP.NET MVC, you can use the Razor view engine.

Razor allows you to use C # code after the sign @.

As an example

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

Alternatively, you can use something like @DateTime.Nowto get the current time. My question is: what features can I use? Where do they import Razor from?

+5
source share
3 answers

Any open class. They are imported using @using MyNamespace. You can also import them into the configuration file.

<system.web.webPages.razor>

element.

+7
source

, . .cs. - , web.config, , .cs.

@using System.Collections.Generic;

+3

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

+1
source

All Articles