We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Can i put JS-Render template in separate javascript file?

Thread ID:





120128 Sep 3,2015 06:06 AM UTC Sep 4,2015 10:36 AM UTC JavaScript 1
Tags: ejGrid
Rakesh Advani
Asked On September 3, 2015 06:06 AM UTC


I am using syncfusion angular grid with some template binding you can make your self more clear by refer below code snippet.

This code in javascript:

$scope.columns = [
                        { field: "name", headerText: resource.templateName, template: "true", templateID: "#nameUrlTemplate", width: 300 },
                        { field: "description", headerText: resource.description, template: "true", templateID: "#descriptionUrlTemplate", width: 400 }

This code in CSHTML:

<script type="text/x-jsrender" id="nameUrlTemplate">
    {{if name != ""}}
    <a rel='nofollow' href="@Url.Action("Edit", "Home")?agenttypeid={{:agentTypeId}}&templateversion={{:templateVersion}}&dataSourceType={{:dataSourceType}}">{{:name}}</a>
<script type="text/x-jsrender" id="descriptionUrlTemplate">
    {{if description != ""}}
    <a rel='nofollow' href="@Url.Action("Edit", "Home")?agenttypeid={{:agentTypeId}}&templateversion={{:templateVersion}}&dataSourceType={{:dataSourceType}}">{{:description}}</a>

this code is working very fine but i placed it in cshtml file. so problem is i have to follow some coding standard and because of that i have to put this code code in separate javascript file as per codding  standard.

so is there any way to put this code in separate javascript.

aspect quick reply.

Many thanks,

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On September 4, 2015 10:36 AM UTC

Hi Rakesh,

Thanks for contacting Syncfusion support.
Your requirement is to include the Jsrender template in a separate js file. In your code example, there is a serverside code, which is a razor syntax.

<script type="text/x-jsrender" id="nameUrlTemplate">

        {{if name != ""}}

        <a rel='nofollow' href="@Url.Action(" edit", "Home" )?agenttypeid={{:agentTypeId}}&templateversion ={{:templateVersion}}&dataSourceType ={{:dataSourceType}}">{{:name}}</a>



Normally, if any razor syntax is given in the view, the razor engine will parse it and build a respective view. The Razor parser itself is designed to process a stream of characters given in the View, to generate a C# or VB class which can be compiled.
The razor engine is able to parse only the razor syntax present in the view or any JS code embedded inline in the view. The Razor engine will not parse the external JS file referred in the page. Hence, place the template in the view if you want to use server codes inside the template string.
Seeni Sakthi Kumar S.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon