This is a migrated thread and some comments may be shown as answers.

CheckBoxFor with Label and raw HTML

1 Answer 817 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
NovaStor
Top achievements
Rank 1
NovaStor asked on 08 Nov 2019, 09:40 PM

Hi.

I'd like to display a checkbox with a label that contains HTML.

 

For example:

 

Model:

 

[Display(Name = "I agree to the <a href=\"{0}\">Terms and Conditions</a>")]

public bool IAgreeToTheTermsAndConditions { get; set; }

 

View:

 

@Html.Kendo().CheckBoxFor(model => model.IAgreeToTheTermsAndConditions).Label(

                            string.Format(

                                Html.DisplayNameFor(model2 => model2.IAgreeToTheTermsAndConditions).ToString(),                                 @Url.Action("TermsAndConditions", null)))

 

However, the label is rendered with the HTML encoded:

I have agree to the &amp;lt;a href=&amp;quot;/TermsAndConditions&amp;quot;&amp;gt;Terms and Conditions&amp;lt;/a&amp;gt;

 

How can I pass raw HTML to the Label?

 

Thank you.

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 12 Nov 2019, 04:06 PM

Hello,

As we are using basic Html helpers the behavior you are experiencing is not something we have control over. The encoding is MVC specific. As a possible solution, I could suggest creating a custom Html helper which will make the checkbox with the label as a link. More information can be obtained at the following StackOverflow thread: https://stackoverflow.com/a/30476657/12355063

Another alternative would be creating a resource file that returns strings. Information about this at the below links:

Please let me know if you have other questions.

Regards,
Nikolay
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
NovaStor
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or