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

Call View Model Method within ClientTemplate

2 Answers 309 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 06 Feb 2013, 11:50 PM
I am having difficulty trying to figure out how to convert our server side grid to ajax grid due to some road blocks.  We are upgrading our grid from the older Telerik MVC extensions grid to the new Kendo UI grid and I have run into a couple of issues with converting some conditional statements to be usable within the ClientTemplate. Can anyone assists on the correct way to convert the following line of code to be compatible with ClientTemplate?

columns.Template(@<text>
            @if(String.IsNullOrEmpty(Model.DownloadURL(item.DocumentId,item.Name, item.ExtUrl)))
             {   }
             else
             {
                   <a href="@Model.DownloadURL(item.DocumentId,item.Name,item.ExtUrl)" title="Click to download">
 
             }</text>).Title("Download")

I was able to do 
columns.Bound(p=>p.DocumentId).ClientTemplate(String.IsNullOrEmpty(@Model.DownloadURL("#=DocumentId#","#=Name#","#=ExtURL#)).ToString()).Title("Download")
To get true or false returned from the method call, but I cannot figure out how to place the result returned into a conditional if-else statement to determine which html should display based on the condition as shown in the original code.

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Feb 2013, 01:28 PM
Hello,

i have used model this way in my code please check it. It might be help you.

columns.Template(@<text></text>).Title("Action").ClientTemplate(
                "# if (ErrroCount <= " + @Model.ErrorThreshold + ") { #" +
                         "<a class=\"edit margin_l10\" onclick=\"SetEditMode(#= ID #);\" id=\"btnEdit\" title=\"Edit\"> Edit</a>" +
                    "# } #"
                );

For file download in kendo Grid.
http://jayeshgoyani.blogspot.in/2013/01/download-files-from-grid-in-kendo-ui.html

Thanks,
Jayesh Goyani
0
Greg
Top achievements
Rank 1
answered on 07 Feb 2013, 05:09 PM
Thanks, that helped greatly and I was able to complete the rest of the conversion of our grid.  Another quick question.  When the grid loads it appears to display the server side grid, then converts to the client side grid.  Is there anyway to avoid this?
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Greg
Top achievements
Rank 1
Share this question
or