给定一个名为SomeContainer.spark的spark视图,它以这种方式使用局部视图:
<SomeContent param1 = "Model.SomeValue"/>并给出一个名为SomeContent.spark的局部视图,它以这种方式使用参数:
<div>${param1}</div>如何修改SomeContent.spark以预先声明param1。 我想这样做有两个原因:
可读性:读者将知道部分视图所依赖的内容 在Visual Studio中获得param1的intellisence我试图在SomeContent.spark中简单地声明相同的<var> ,但它在运行时失败,表明该变量已经存在。
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 StudioI tried to simply declare the same <var> in SomeContent.spark but it fails at runtime indicating that that variable already exists.
最满意答案
我得到了Spark集团的答案。 在partial中,您可以使用<default/>元素声明变量:
<default param1="new List<string>()" type="List[[string]]"/>它不仅声明参数(具有我的问题中提到的优点),而且还给它一个默认值,可以用来防止部分表单获得NullReferenceException ...
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...
更多推荐
发布评论