I have successfully set up a Kendo Grid using MVC4 and Razor syntax. This grid is designed to show log entries retrieved from a database table. The LogText column in the database contains text with Windows newline characters that I want to replace with line break tags for better readability on the front-end. In order to achieve this, I created a JavaScript function that will be called from a column template within the grid. The grid itself utilizes server binding. However, I am having trouble finding the correct syntax to make a JavaScript call from within the template, especially with Razor syntax involved. Any assistance or guidance on this matter would be greatly appreciated.
Below is a snippet of my code:
@model IEnumerable<Core.Models.ShipmentLog>
@{
ViewBag.Title = "ShipmentLog";
}
<h2>ShipmentLog</h2>
@(Html.Kendo().Grid(Model)
.Name("ShipmentLogGrid")
.Columns(columns=>
{
columns.Bound(bl => bl.UserName);
columns.Bound(bl => bl.LogTime);
columns.Bound(bl => bl.LogType);
columns.Bound(bl => bl.LogText).Width(600).Encoded(false).Template(#= GetHtmlNewLinesString(@item.LogText) #);
})
)
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">
function getHtmlNewLinesString(text) {
return text.replace('\n/g', '<br />');
}
</script>