星火视图引擎绑定与HTML类属性 [英] Spark View Engine Bindings with Class Html Attribute

查看:228
本文介绍了星火视图引擎绑定与HTML类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用绑定与火花视图引擎功能来代替相当一部分的我HTML辅助方法调用。

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

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

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:

绑定:

<element name="Editor">Html.EditorFor(x => x.@For, new {"@*"}) </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"}) );

问题显然是我需要的,而不是使用类@class。

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

不过,我不能指定的HTML属性@class这样

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

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

由于火花忽略它。

我也不能指定它是这样的:

I also can't specify it like this:

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

由于那么被穿过每个HTML属性将与@符号pfixed $ P $。

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

所以我的问题是,我怎么能传递 HTML通过对火花用它来初始化一个字典参数,以便它不会抛出时绑定属性编译器错误?

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?

推荐答案

你在你的观察是正确的。在你的绑定正确的语法,我相信会是这样的:

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>

而不是

<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

这篇关于星火视图引擎绑定与HTML类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆