Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:33:25+00:00 2026-05-28T07:33:25+00:00

In a normal C# code I can use a using statement to define an

  • 0

In a normal C# code I can use a using statement to define an alias for a class name, e.g.

using MyAlias = Some.Long.Namespace.Class;

I have tried the same in a razor view, a naive approach like

@using MyAlias = Some.Long.Namespace.Class

does not work. Is there any way to achieve the same effect ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:33:26+00:00Added an answer on May 28, 2026 at 7:33 am

    Why would you want to do that? Whatever reason you need this for, there’s probably a better way. You should avoid writing C# code in a Razor view anyway, so you shouldn’t need it. All you need in a Razor view is the namespace for your view model because that’s all that a view should manipulate.

    @model MyViewModel
    ...
    

    Leave the aliases and C# code to where they belong – controllers, models, helpers, …

    All this being said, the aliases should work. For example the following view runs perfectly fine for me:

    @using foo = System.IO;
    <div>
        @foo.Path.GetFileName(@"c:\work\foo.txt")
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a normal asp.net page containing some code that I want to measure
I have acustom sharepoint page. on my machine I can debug the code normaly
What is the normal way people writing network code in Delphi use Windows-style overlapped
Is it normal to have tests that are way bigger than the actual code
i have this CSS code: h1 { font-size:22px; color:#341C12; font-weight:normal; font-style:italic; } .h1color h1{
I've been given some Symbian C++ code to port over for use with the
I have to download a file and I'm using this code , which is
Can anyone pls tell me that, why I can't use normal C++ classes within
Using the Entity Framework 4. I have created a Code First database in the
I use Devexpress ASP.NET component. My question is; Can i use Devexpress Exporting Code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.