I need to alias a type with a using
directive, which is normally done like so:
using LocalResources = Resources.Admin.SomeResource;
How can I do this inside my Razor view so that I can then use it like @LocalResources.FirstName
?
The Razor content page requires the @page directive at the top of the file. The HasFormContentType property is used to determine whether a form has been posted and the Request. Form collection is referenced within a Razor code block with the relevant value within it assigned to the name variable.
cshtml file, you will still need to use @using . The @namespace directive was designed so the C# classes added to a project and pages-generated code just work without having to add an @using directive for the code behind file.
New @model directive Let's now look at a new feature we added with the ASP.NET MVC 3 Beta – the @model directive. The @model directive provides a cleaner and more concise way to reference strongly-typed models from view files.
Here is how
@using File = System.IO.File //at the top of the page then
// use @File any where in the cshtml page.
Razor does not currently support type or namespace aliasing. This is something that we might consider for future versions.
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