-
-
Save krishnabharath/7430720 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TO USE: | |
Simply tack on .ToMvcClientTemplate() to the end of the outer-most MVC helper | |
that you're trying to turn into a template. | |
In this example: http://demos.kendoui.com/web/grid/detailtemplate.html, you | |
would add it after the last ToClientTemplate() that occurs before the script | |
section with the "function databound()" handler. | |
Note that returning an HtmlString instead of an MvcHtmlString will ensure you | |
don't have to call @Html.Raw() in your template to bypass the AntiXss encoding | |
that will be performed when MvcHtmlString.ToString() is called. | |
Feel free to lean hard on Telerik to get their ToClientTemplate() code changed | |
to include this technique. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Kendo.Mvc.UI; | |
using System.Web; | |
using System.Web.Mvc; | |
using System.Web.Security.AntiXss; | |
using System.Web.Util; | |
namespace Your.Namespace.Here | |
{ | |
public static class KendoMvcExtensions | |
{ | |
public static IHtmlString ToMvcClientTemplate(this MvcHtmlString mvcString) | |
{ | |
if (HttpEncoder.Current.GetType() == typeof (AntiXssEncoder)) | |
{ | |
var initial = mvcString.ToHtmlString(); | |
var corrected = initial.Replace("\\u0026", "&").Replace("%23", "#").Replace("%3D", "=").Replace(" ", " "); | |
return new HtmlString(corrected); | |
} | |
return mvcString; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment