如何在局部视图中声明参数(变量)?
给定一个名为 SomeContainer.spark
的 Spark 视图,它以这种方式使用分部视图:
<SomeContent param1 = "Model.SomeValue"/>
并给定一个名为 SomeContent.spark
的分部视图,它以这种方式使用参数:
<div>${param1}</div>
我该如何修改SomeContent.spark
预先声明 param1。我想这样做有两个原因:
- 可读性:读者会知道分部视图取决于什么 为了
- 在 Visual Studio 中获取 param1 的智能,
我尝试在 SomeContent.spark 中简单地声明相同的 但它在运行时失败,表明该变量已经存在。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从 Spark 小组得到了答案。在部分中,您可以使用
元素声明变量:它不仅声明参数(具有我的问题中提到的优点),而且还为其提供了一个默认值可用于防止部分表单出现 NullReferenceException...
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...