Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an Edit column to a telerik grid using ASP.Net MVC 2 and Telerik MVC (2010 Q1)

I have been successful with creating a Telerik grid to display a list of products, however I've gone through some difficulty adding the column to allow a user to edit (I'm not even trying to edit within the grid - I simply want a link to an edit view)

When I add the custom column, I get the following lines in my error screen when I debug (Line 24 in red):

Line 22:                          columns.Add(o => o.ProductIsActive);
Line 23:                          columns.Template(o =>
Line 24:                          {
Line 25:                              
Line 26:                              %><%=Html.ActionLink("Edit", "Edit", new { id = o.ProductID })%><% }).Title("Edit");

My Compiler Error Message is Compiler Error Message: CS1525: Invalid expression term ')'

Here is my View Code:

<%= Html.Telerik().Grid<NationalPetVax.Models.Product>()
          .Ajax(ajax => ajax.Action("_Index", "Products"))
          .DataKeys(dataKeys => dataKeys.Add(c => c.ProductID))
          .DataBinding(dataBinding => dataBinding.Ajax().Update("Update", "Home"))

          .Name("Grid")
                 .Columns(columns =>
                 {
                     columns.Add(o => o.ProductName).Width(81);
                     columns.Add(o => o.ProductPrice).Width(200);
                     columns.Add(o => o.ProductType.ProductTypeName);
                     columns.Add(o => o.Specy.SpeciesName);
                     columns.Add(o => o.ProductIsActive);
                     columns.Template(o =>
                     {

                         %><%=Html.ActionLink("Edit", "Edit", new { id = o.ProductID })%><% }).Title("Edit");

                     })
          .Sortable()
          .Scrollable()
          .Pageable();
    %>

Has anyone ever seen this issue? I have followed the tutorials over and over and am about to give up on the telerik grids all together, although I really like them and want to include in my projet.

like image 324
Ben Avatar asked Feb 21 '10 17:02

Ben


2 Answers

I don't know about Telerik. But it looks like the problem is about the closing/opening tags inside the expression. Try this :

columns.Template(o =>
              { 
                  Response.Write(Html.ActionLink("Edit", "Edit", 
                  new { id = o.ProductID })); 
              }).Title("Edit");
like image 74
Çağdaş Tekin Avatar answered Dec 17 '22 22:12

Çağdaş Tekin


The following code will solve your issue and will make code little tidy.

columns.Bound(o => o.ProductId).Format(
             Html.ActionLink("Edit", "Edit", new {Id = "{0}"}).ToString());

Also Bound is the new Add in 2010 Q1 release

like image 22
suhair Avatar answered Dec 17 '22 23:12

suhair