Feature Overview
- compiled views
- use strong typed (with c#) view/viewcomponent properties
- plain asp/php/jsp like syntax
- support viewfilters, viewcomponents, layouts
Getting AspView
You can always get the compiled binaries from http://www.aspview.com
, or you can grab the sources from http://svn.castleproject.org:8080/svn/castlecontrib/viewengines/aspview/
and build yourself.
Crash Course
What template code look like?
<%@ Page Language="C#" Inherits="Castle.MonoRail.Views.AspView.ViewAtDesignTime" %> <%@ import namespace="MyOrg.Model"%> <aspView:properties> <% User currentUser; %> </aspView:properties> Hello <%=currentUser.Shortname%>. <%if(currentUser.IsAccountExpired){%> your account is expired <%}else{%> <a href="proceed">proceed</a> <%}%> <% foreach (User friend in currentUser.Friends) { %> <subView:Friend friend="<%= friend %>" ></subView:Friend> <% } %> <component:componentname param1="<%=currentUser%>" param2="constant"> <sectionname>content</sectioname> </component:componentname>
web.config setup
add the following section in config/configSections
<section name="aspview" type="Castle.MonoRail.Views.AspView.AspViewConfigurationSection, Castle.MonoRail.Views.AspView" />
add Castle.MonoRail.Views.AspView.AspViewEngine, Castle.MonoRail.Views.AspView to the viewengine configuration in config/monorail:
<monoRail>
...
<viewEngine
viewPathRoot="Views"
customEngine="Castle.MonoRail.Views.AspView.AspViewEngine, Castle.MonoRail.Views.AspView" />
...
</monoRail>
add the following section in config
<aspview saveFiles="true|false" autoRecompilation="true|false" debug="true|false"> <reference assembly="AddYourAssembliesInThisSection.dll"/> </aspview>
that's it.
Using a 'Precompiled' mode
When it's time to move to production, you should deploy a precompiled version of your views. In order to do so, you should put VCompile.exe in your site's bin folder, and run it once. A precompiled views assembly named 'CompiledViews.dll' would get created, and you can then deploy that file to your application's bin folder on the server.
In order to tell AspView to load the views from the precompiled assembly, go to the configuration section of aspview, and set autoRecompilation to 'false':
<aspview saveFiles="false" autoRecompilation="false" debug="false"> <reference assembly="AddYourAssembliesInThisSection.dll"/> </aspview>
Precompiled mode on development enviroment
If you want, you can use the precompiled mode on your development machine. just setup a PostBuild event on your site's project, to copy VCompile.exe to your site's bin folder and run it:
copy $(SolutionDir)YOUR_SHARED_LIB_FOLDER\vcompile.exe $(TargetDir) $(TargetDir)vcompile.exe
