如何在局部视图中声明参数(变量)?(How to declare parameters (variables) in a partial view?)

编程入门 行业动态 更新时间:2024-10-28 15:21:34
如何在局部视图中声明参数(变量)?(How to declare parameters (variables) in a partial view?)

给定一个名为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 Studio

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

更多推荐

本文发布于:2023-08-04 15:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   变量   局部   声明   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!