Suresh R
Suresh R

Reputation: 249

How to add data attributes in Sitecore MVC fileds

My code:

<a data-toggle="dropdown">Associate Sites<i class="fa fa-angle-down"></i></a>

I tried following code:

namespaces:

@using System.Web.Mvc
@using Sitecore.Mvc
@using Glass.Mapper.Sc
@using Sitecore.Mvc.Presentation
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<CassiaMvc.Models.Footer>

Code:

  @Html.Sitecore().BeginField("Link Field", new { @data-toggle="dropdown" })
  @Html.Sitecore().Field("Destination URL", item)
  @Html.Sitecore().EndField()

But I getting error, enter image description here

Please let me know what am doing wrong.

Upvotes: 0

Views: 2203

Answers (1)

Richard Seal
Richard Seal

Reputation: 4266

You can't use hyphens for property names in a dynamic object. Change the hyphens to underscores:

 @Html.Sitecore().BeginField("Link Field", new { @data-toggle="dropdown" })

to

@Html.Sitecore().BeginField("Link Field", new { @data_toggle="dropdown" })

The field renderer should convert the underscores to hyphens when rendered.

Upvotes: 3

Related Questions