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

Template Columns with Razor Syntax in ASP.NET MVC Telerik Grid

9 Answers 1108 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
James
Top achievements
Rank 1
James asked on 13 Nov 2010, 04:07 PM
How do I define Template columns with Razor syntax in Telerik's ASP.NET MVC Grid?  The examples you have in your demos use <% %> syntax like the following:

<% Html.Telerik().Grid(Model)
       
.Name("Grid")
       
.Columns(columns =>
       
{
           
//Template column. The grid displays the HTML defined by the argument.
           
columns.Template(c => {
            %>
                <img
                    alt="
<%= c.CustomerID %>"
                    src="
<%= Url.Content("~/Content/Grid/Customers/" + c.CustomerID + ".jpg") %>"
                  />
           
<%
           
});

           
//Regular databound column. The grid displays the value of the CustomerID property.
            columns
.Bound(c => c.CustomerID);
       
})
       
.Render();
 %>
How do I achieve the same thing when working with the new Razor syntax?

Thanks,
James Foster

9 Answers, 1 is accepted

Sort by
0
a c
Top achievements
Rank 1
answered on 14 Nov 2010, 03:54 PM
please visite the MVC 3 Razor Demo: http:\\mvcdemo.chiplex.com
0
Mike Kidder
Top achievements
Rank 1
answered on 16 Nov 2010, 10:26 PM
@a c

Nice work, did you get this setup yourself?  I am assuming that is the case, I don't see it available yet via Telerik's website.
0
Ian
Top achievements
Rank 1
answered on 19 Nov 2010, 01:27 AM
Although the site is showing demos that make use of the razor syntax, when you go to download the source code for version 2010.3 1110, it's still referencing the old MVC 2.0 assemblies and isn't making use of Razor. Is the link broken?
0
Mike Kidder
Top achievements
Rank 1
answered on 19 Nov 2010, 03:35 AM
@Ian - that link for the MVC3 demo (using the razor view engine) is not hosted by Telerik, and was presumably setup by "a c".   However, all the links within the example point back to Telerik's website.  

Check out this blog post on the Telerik blog site for an MVC3 specific build of the Telerik.Web.Mvc assembly (build 2010.3.1110.340) by Rosen Konstantinov.    You can use this assembly and copy/paste from that razor demo(s) until an official download from Telerik becomes available.
0
Ian
Top achievements
Rank 1
answered on 19 Nov 2010, 07:42 PM
That still doesn't show how to do template columns under razor. Is that not available yet?
0
Mike Kidder
Top achievements
Rank 1
answered on 19 Nov 2010, 09:19 PM
Thanks Ian, I should have more directly answered James initial question.  Yes, template's work just fine in the Razor syntax.  Let's translate Jame's code to razor:

@(Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
           @* Template column. The grid displays the HTML defined by the argument. *@
            columns.Template(@<text>
                <img alt="@item.CustomerID"
                    src="@Url.Content("~/Content/Grid/Customers/" + @item.CustomerID + ".jpg")"
                  />
                </text>);
           @* Regular databound column. The grid displays the value of the CustomerID property. *@
            columns.Bound("CustomerID");
        })
)

Notice within Razor that the .Render() syntax is not needed.  The razor comment blocks used above are supported in Visual Studio toolbar.  We could have used @// for single line comments.  Hope that answers your question.
0
Rabiu
Top achievements
Rank 1
answered on 25 Nov 2010, 05:25 PM
Hi, is there a place I can download the complete razor sample?

Also, I have problem with intellisence, for example in the code below intellisense works on the 'mappings' argument but on the 'binding' argument i notice there is no more intellisense. Do you know what the problem might be?

Thanks.

@(Html.Telerik().PanelBar()
        .Name("PanelBar")
        .BindTo(Model, mappings => 
        {
            mappings.For<DirectDebit.Web.Models.NavigationModel>(binding => 
                binding.ItemDataBound((item, navigation) =>
                    {
                        item.Text = navigation.Action;
                    }));
        })
  )
0
Steve Gentile
Top achievements
Rank 1
answered on 02 Jan 2011, 10:52 PM
FYI: if you use the nuget package manager you can pull down a working version of mvc 3
0
Azwaan
Top achievements
Rank 1
answered on 10 Jan 2011, 12:56 PM
The demo site ( http:\\mvcdemo.chiplex.com)  for MVC razor no longer works. is there an alternative site?
Tags
General Discussions
Asked by
James
Top achievements
Rank 1
Answers by
a c
Top achievements
Rank 1
Mike Kidder
Top achievements
Rank 1
Ian
Top achievements
Rank 1
Rabiu
Top achievements
Rank 1
Steve Gentile
Top achievements
Rank 1
Azwaan
Top achievements
Rank 1
Share this question
or