0

I would like to use a use an alias in my views to make the code more expressive, so I have tried permutations of the following

namespace RES.Project.MVC.ViewModels
{
    using ECMAlertListUrl = System.String;
}

and in the view

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<RES.Project.MVC.ViewModels.ECMAlertListUrl>" %>

I have done some experimentation / reading, and I think this isn't possible as the using directive is scoped to the containing namespace or compilation unit (eg .cs file), but if anybody can probe me wrong or has any other suggestions then I'm all ears.

cedd
  • 1,741
  • 1
  • 21
  • 34
  • How about this? http://stackoverflow.com/questions/1697169/is-it-possible-to-use-the-using-statement-in-my-aspx-views-asp-net-mvc – DavidG Jun 26 '15 at 08:38
  • I couldn't get that to work, I think because the using directive is scoped to the namespace, but is not contained in the namespace, if that makes sense. Eg. MyNamespace.MyAlias is not valid syntax. – cedd Jun 26 '15 at 09:05
  • I don't think you can use an alias. Not sure why you would want to though, they are usually only used to avoid conflicts. Renaming things can lead to confusion. – DavidG Jun 26 '15 at 09:30

0 Answers0