如何在局部视图中声明参数(变量)?

发布于 2024-08-22 08:10:20 字数 507 浏览 5 评论 0原文

给定一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苹果你个爱泡泡 2024-08-29 08:10:20

我从 Spark 小组得到了答案。在部分中,您可以使用 元素声明变量:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文