Created
November 10, 2011 14:27
-
-
Save anonymous/1354958 to your computer and use it in GitHub Desktop.
Example of a base view for razor with RouteInfo property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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