Given a spark view named SomeContainer.spark that uses a partial view this way:
<SomeContent param1 = "Model.SomeValue"/>
and given a partial view named SomeContent.spark that uses the parameter this way:
<div>${param1}</div>
How can I modify SomeContent.spark to declare param1 upfront. I want to do that for two reasons:
- Readability: readers will know what the partial view depends on
- To get intellisence for param1 in Visual Studio
I tried to simply declare the same <var> in SomeContent.spark but it fails at runtime indicating that that variable already exists.
I got the answer from the Spark group. In the partial you can declare a variable using the
<default/>element:Not only does it declare the parameter (with the advantages mentioned in my question) but it also gives it a default value which can be used to prevent the partial form getting a NullReferenceException…