Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can the using directive be placed in ASP.NET Razor pages?

I've traditionally always put @using directives in my ASP.NET Razor pages at the top, along with the @model directive. However, for my overall layout, I want to make sure the DOCTYPE declaration is at the very beginning of the document, so I want to push the @using down a bit. Would you following be valid?

<!DOCTYPE html>
<html>
    @using My.Library;
    <head>
        <title>Test web page</title>
        ...

Also, is there any documentation on where the @using directive can be used in Razor pages? I can't seem to find any. Is it valid to use it after some other Razor code, for example, or does it have to appear first?

like image 730
Jez Avatar asked May 21 '13 15:05

Jez


1 Answers

It is valid and you can use @using any where before that you need that library.

MSDN:

HTML markup lines can be included at any part of the code.

so you can put DOCTYPE at the top of page.

like image 100
Majid Avatar answered Oct 04 '22 20:10

Majid