如何使用Sitecore Glass Mapper渲染与css类的链接 [英] How to render link with css class with Sitecore Glass Mapper

查看:111
本文介绍了如何使用Sitecore Glass Mapper渲染与css类的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下链接:

<a class="btn btn-primary" href="#">View details »</a>

如何使用仍保留css类的sitecore glass渲染链接?使用sitecore中的字段渲染器,您曾经能够将该类作为附加参数传递,这如何与玻璃一起使用?

How can I render the link with sitecore glass that it still keeps the css class? With the field renderer in sitecore you used to be able to pass the class along as additional parameters, how does this work with glass?

这是我到目前为止:

@RenderLink(x => x.Link)

这只会渲染没有类的链接。

This only renders the link without the class though.

任何帮助表示赞赏。 Thx。

Any help appreciated. Thx.

推荐答案

你也可以像这样制作一个启用PageEditor的版本,它应该自动考虑Class属性:

You can also make a PageEditor enabled version like this and it should automatically take the Class attribute into account:

@Editable(Model, x => x.Link)

或者当您使用RenderLink时,您可以传递具有class属性的集合:

Or when you use RenderLink, you can pass a collection with the class attribute:

@RenderLink(x => x.Link, new System.Collections.Specialized.NameValueCollection { { "class", "btn btn-primary" } })

编辑:修改示例到工作代码并添加了可编辑的格式示例

Modified example to working code and added formatting example for Editable

您可以指定格式可编辑:

You can specify a format for Editable:

@(Editable<YourModelType>(Model, x => x.Link, string.Format("<a href=\"{0}\" class=\"btn btn-primary\">{1}</a>", x.Link.Url, x.Link.Text)))

这篇关于如何使用Sitecore Glass Mapper渲染与css类的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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