Why do you need this? Whatever the reason you need is probably the best way. In any case, you should avoid writing C # code in Razor mode, so you wonβt need it. All you need in the Razor view is the namespace for your view model, because everything that needs to be processed must be processed.
@model MyViewModel ...
Leave the aliases and C # code where they belong - controllers, models, helpers, ...
All of this says that aliases should work. For example, the following view works fine for me:
@using foo = System.IO; <div> @foo.Path.GetFileName(@"c:\work\foo.txt") </div>
source share