Skip to content

Instantly share code, notes, and snippets.

Created November 10, 2011 14:27
Show Gist options
  • Save anonymous/1354958 to your computer and use it in GitHub Desktop.
Save anonymous/1354958 to your computer and use it in GitHub Desktop.
Example of a base view for razor with RouteInfo property
@{
ViewBag.Title = "About Us";
}
<h2>About</h2>
<p>
Hi @RouteInfo.name(), welcome to the @RouteInfo.action() action, which is located in the @RouteInfo.controller() controller
</p>
namespace System.Web.Mvc
{
public abstract class CustomRazorViewBase : WebViewPage
{
private DynamicUrlAccessor _accessor;
public CustomRazorViewBase()
{
_accessor = new DynamicUrlAccessor(ViewContext);
}
public dynamic RouteInfo
{
get
{
return _accessor;
}
}
}
public abstract class CustomRazorViewBase<T> : WebViewPage<dynamic>
{
private DynamicUrlAccessor _accessor;
public CustomRazorViewBase()
{
_accessor = new DynamicUrlAccessor(ViewContext);
}
public dynamic RouteInfo
{
get
{
return _accessor;
}
}
}
}
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.CustomRazorViewBase">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment