So I need to add a "using" statement which is :
using System.Data.SqlClient
in my webpage so i dont have to call whats inside the SqlClient with the whole statement
System.Data.SqlClient.SqlConnection con = new ..
How to do that ?
note that i added the reference System.Data to my webconfig file.
Razor pages have handler-methods which are HTTP verbs. So to call a method from your page you need to put On followed by the http verb you want then your method name . And in your view pass the name to the asp-page-handler without the OnPost or OnGet prefix or Async suffix.
Comments Razor View Engine has two types of comments, one is single-line and another is multiline. Razor uses the syntax "@* .. *@" for the comment block but in a C# code block we can also use "/* */" or "//".
In visual studio, select some code/markup in your razor view and press Ctrl+K, Ctrl+C, and it'll comment the selection as described above.
This operator is useful in conjunction with other Razor server side operators when you want to output something as a literal text. For example: @if (model. Foo) { @:Some text to be written directly. }
At the top of your Razor View just add
@using System.Data.SqlClient
Notice the @
char before the using statement.
Or inside a block like below:
@{
using System.Data.SqlClient;
}
Side note: it's a little bit weird to use a SqlConnection
into a Razor View.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With