开发者

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.sp开发者_开发百科ark 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:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜