Sylvain
Sylvain

Reputation: 19269

How to declare parameters (variables) in a partial view?

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:

I tried to simply declare the same <var> in SomeContent.spark but it fails at runtime indicating that that variable already exists.

Upvotes: 3

Views: 794

Answers (1)

Sylvain
Sylvain

Reputation: 19269

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

Upvotes: 5

Related Questions