0

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.

2
  • I tried with @Html.Sitecore().BeginField("Link Field") @Html.Sitecore().Field("Destination URL", item,, new {@data-toggle="dropdown" }) @Html.Sitecore().EndField(), also getting same error. Commented Mar 22, 2016 at 15:28
  • I see you are importing Glass Mapper namespaces. Is there a reason you are not using it? Commented Mar 22, 2016 at 16:04

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, error gone, but not rendered the attribute. <a href="http://" target="_blank" item="Sitecore.Data.Items.Item" isactive="False">Associate Sites</a>
This works in my dev. @Html.Sitecore().Field("Destination URL", item, new { @data_toggle="dropdown" })
Thanks dnstommy, working fine, could you please help me integrate of <i class="fa fa-angle-down"></i> with in link field
I write code like this @Html.Sitecore().Field("Destination URL", item.Item, new { @data_toggle = "dropdown" }) <i class="fa fa-angle-down"></i>, but getting like <a href="/en" data_toggle="dropdown">Associate Sites</a> <i class="fa fa-angle-down"></i> , I would expect like <a data-toggle="dropdown">Associate Sites<i class="fa fa-angle-down"></i></a>
Hello Richard "The field renderer should convert the underscores to hyphens when rendered." this saves my day. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.