3

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.

1 Answer 1

5

I got the answer from the Spark group. In the partial you can declare a variable using the <default/> element:

<default param1="new List<string>()" type="List[[string]]"/> 

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...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.