Visual Basic
Submitted by admin on Tue, 06/30/2009 - 03:59
Table of Contents [hide]
Creating a new project
Assuming you have a Visual Basic ASP.NET MVC web application there are very few things you need to enable Spark. In the end it's very similar to the CSharp implementation.
First, add references to the following assemblies:
- Spark.dll
- Spark.Web.Mvc.dll
Then add the following minimal configuration to change Spark's default target language to Visual Basic:
<configuration> <configSections> ... <section name="spark" type="Spark.Configuration.SparkSectionHandler, Spark"/> </configSections> <spark> <compilation defaultLanguage="VisualBasic"/> </spark> ... </configuration>
You'll also want to ensure the <system.codedom> configuration contains a definition of visualbasic which targets the v3.5 framework or higher.
Finally add the following to your Global.asax file:
Shared Sub RegisterViewEngines(ByVal engines As ViewEngineCollection)
SparkEngineStarter.RegisterViewEngine(engines)
End Sub
Sub Application_Start()
....
RegisterViewEngines(ViewEngines.Engines)
End SubAdding views
At this point everything about Spark works exactly as it does normally with the exception that the CLR syntax used is Visual Basic. Another place to check out VB syntax in Spark is located at Samples\AspNetMvc\VisualBasicViews.
#' this is a comment <!-- Dim x = 4 + 5 --> <var x="4 + 5"/> <!-- Dim xx As Invoice = Nothing --> <var xx="Nothing" type="Invoice" /> <!-- Note: single = used instead of == --> <test if="x = 9"> <!-- Note: VisualBasic does not require 'var' in foreach loop <!-- For Each prod in Products --> <for each="prod in Products"> </for> <!-- and you can provide type in the loop with optional 'As' --> <for each="p As Product in Products"> </for> </test> <!-- And the rest is about like you'd expect --> #Using Html.BeginForm() <!-- although the anonymous object syntax is a bit odd --> !{Html.ActionLink("Show Order", "View", New With {.id = MyOrderId} ) } #End Using
