Spark View 引擎与类 Html 属性的绑定

发布于 2024-10-01 09:50:26 字数 1155 浏览 0 评论 0原文

我一直在使用 Spark View 引擎的 Bindings 功能来替换我的一些 Html 帮助器方法来电。

我遇到的一个问题是我想定义一个 css 类来传递给辅助方法的匿名字典参数,我通常会这样做:

${Html.EditorFor(x=>x.Username, new{@class = "css-class"})}

用 Spark 替换它 绑定看起来像这样:

Binding:< /strong>

<element name="Editor">Html.EditorFor(x => x.@For, new {"@*"}) </element>

查看元素:

<Editor For="Password" class="css-class" />

我收到错误“命名空间不能直接包含字段或方法等成员”,这是有效的,因为它解决了

Output.Write(Html.EditorFor(x => x.Password, new {class="big"}) );

问题显然是我需要使用@class的班级。

但是,我无法像这样在 html 属性中指定 @class

<Editor For="Password" @class="css-class" />

因为 Spark 会忽略它。

我也不能这样指定它:

<element name="Editor">Html.EditorFor(x => x.@For, new {@"@*"}) </element>

因为这样传递的每个 html 属性都会以 @ 符号为前缀。

所以我的问题是,在使用它初始化字典参数时,如何将 class HTML 属性传递给 Spark 绑定,以便它不会引发编译器错误?

I've been using the Bindings feature with the spark view engine to replace quite a few of my Html helper method calls.

One problem I have is that I want to define a css class to pass in to the anonymous dictionary parameter of the helper methods, which I would normally do like this:

${Html.EditorFor(x=>x.Username, new{@class = "css-class"})}

Replacing this with a spark Binding looks like this:

Binding:

<element name="Editor">Html.EditorFor(x => x.@For, new {"@*"}) </element>

View Element:

<Editor For="Password" class="css-class" />

I get an error "A namespace cannot directly contain members such as fields or method" which is valid because it is resolving to

Output.Write(Html.EditorFor(x => x.Password, new {class="big"}) );

The issue is obviously that I need to use @class instead of class.

However, I can't specify @class in the html attribute like this

<Editor For="Password" @class="css-class" />

Because spark ignores it.

I also can't specify it like this:

<element name="Editor">Html.EditorFor(x => x.@For, new {@"@*"}) </element>

Because then every html attribute that gets passed through will be prefixed with the @ symbol.

So my question is, how can I pass the class HTML attribute through to the spark binding when using it to initialize a dictionary parameter so that it doesn't throw a compiler error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

满意归宿 2024-10-08 09:50:26

你的观察是正确的。我认为绑定中的正确语法类似于:

<element name="Editor">Html.EditorFor(x => x.@For, new Dictionary[[string,object]]{{"@*"}}) </element>

而不是

<element name="Editor">Html.EditorFor(x => x.@For, new {"@*"}) </element>

这样,您在视图中附加到标记的任何未按名称专门处理的属性都将作为渲染输出上的名称值对属性传递。

我希望我的语法正确,这对你有用吗?

一切顺利,

You're correct in your observations. The correct syntax in your binding I believe would be something like:

<element name="Editor">Html.EditorFor(x => x.@For, new Dictionary[[string,object]]{{"@*"}}) </element>

instead of

<element name="Editor">Html.EditorFor(x => x.@For, new {"@*"}) </element>

That way, any attributes you attach to your tag in the view that are not specifically taken care of by name, will pass through as name value pair attributes on the rendered output.

I hope I got the syntax right, does that work for you?

All the best,
Rob

青衫负雪 2024-10-08 09:50:26

很抱歉劫持这个问题。但对于任何从绑定开始的人来说,如果您使用稳定的 Spark 1.1.0,我认为存在一些关于 # 和 child::* 的绑定的错误。解决方法是使用开发 Spark 构建。

如果情况并非如此,希望罗伯特能纠正我。但如果是的话,那么也许这会让初学者(像我一样)避免一些最初的困惑。

Sorry to hijack this question. But for anyone starting with bindings, if you are using the stable Spark 1.1.0, I think there are a couple bugs regarding bindings with # and child::*. The fix being to use the development spark build.

If this is not the case, hopefully Robert will correct me. But if it is, then perhaps this will allow beginners (like myself) to avoid some initial confusion.

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