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

[Solved] Compilation Error: Using Ajax related grid wif editing

10 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Li Billy
Top achievements
Rank 1
Li Billy asked on 05 Mar 2010, 03:56 PM
I am using MVC 1. I encountered a problem when trying to use the code in demo of AJAX related Grid with editing. What I did is putting :

            columns.Add(c =>
           {
               
               
               
                %>
                <%= Html.ActionLink("Edit", "Edit", new { id = c.CourseId },
                        new { @class = "t-link action-edit" })%>
                
                <%
        }).Title("Actions").Width(150);

into my workable view:

    <%= Html.Telerik().Grid<Course>()
                .Name("MyCourses")
        .Columns(columns=>
        {
            columns.Add(c => c.CourseId).Width(60);
            columns.Add(c => c.University).Width(250);
            columns.Add(c => c.CourseName).Width(300);
            columns.Add(c => c.CourseCode).Width(60);
            columns.Add(c => c.CourseYear).Width(60);

            columns.Add(c =>
           {
               
               
               
                %>
                <%= Html.ActionLink("Edit", "Edit", new { id = c.CourseId },
                        new { @class = "t-link action-edit" })%>
                
                <%
        }).Title("Actions").Width(150);


            columns.Add(c => c.CourseSemester).Width(60);
        })
                .Ajax(ajax => ajax.Action("_UserCourseList", "Course"))
                .Pageable(paging =>
                    paging.PageSize(2)
                          .Style(GridPagerStyles.NextPreviousAndNumeric)
                          .Position(GridPagerPosition.Bottom)
        )
        .Sortable()
        .RowAction(row =>
        {
            if (row.DataItem.CourseId == 1)
            {
                row.HtmlAttributes["class"] = "t-state-selected";
            }
        })
                .BindTo((IEnumerable<Course>)ViewData["UserCourseList"])
%>




the funny thing is that, the compiler would yell for adding a ";" behind                 .BindTo((IEnumerable<Course>)ViewData["UserCourseList"]), which is not required before.

After I add a ";" to the view, it's fine in Visual Studio 2008, but when I go into debug mode, I got the following message:

Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

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

Source Error:

[No relevant source lines]


Source File:    Line: 0

Is there any solution so that I can edit my related grid data?

Thanks in advance =)
Billy

10 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 05 Mar 2010, 03:59 PM
Hello Li Billy,

Please check this help topic (column definition and templates). It would help you solve this compilation error.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Li Billy
Top achievements
Rank 1
answered on 05 Mar 2010, 04:24 PM
Thank you very muck for your quick reply. I have read your post, it mentioned:

If you need template columns the <% Html.Telerik().Grid().Render(); %> definition should be used instead of <%= Html.Telerik().Grid() %>

if I would like to use this method:

//Template column which shows an action link
columns.Template(o =>
{
%>
<%= Html.ActionLink("Edit", "Home", new { id = o.OrderID }) %>
<%
}).Title("Edit");


However, no matter I add the Render() or not, it has got the following message in VS 2008 Compiler;

Error    1    'Telerik.Web.Mvc.UI.GridColumnFactory<MyFYP.Models.Course>' does not contain a definition for 'Template' and no extension method 'Template' accepting a first argument of type 'Telerik.Web.Mvc.UI.GridColumnFactory<MyFYP.Models.Course>' could be found (are you missing a using directive or an assembly reference?)    c:\Users\Billy\Desktop\Workable FYP\MyFYP - Copy (2)\MyFYP\Views\Course\UserCourseList.aspx    27    21    MyFYP


It seems I can't use template here, am I right? If that's the case, what else I can try?

Many thanks =)
Billy
0
Atanas Korchev
Telerik team
answered on 05 Mar 2010, 04:35 PM
Hello Li Billy,

The documentation link I've sent you is for the Q1 2010 Futures release while you seem to be using Q3 2009 where the Template method is not available.

Please check this online demo. It should how to use templates.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Li Billy
Top achievements
Rank 1
answered on 05 Mar 2010, 05:09 PM
Oh, I have tried the latest version of Telerik for making the Template possible, but still it has the same error as before.

@@"
0
Atanas Korchev
Telerik team
answered on 05 Mar 2010, 05:20 PM
Hi Li Billy,

Here is the code from Template columns example

<% 
    Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Template(c => {
                %><img
                    alt="<%= c.CustomerID %>"
                    src="<%= Url.Content("~/Content/Grid/Customers/" + c.CustomerID + ".jpg") %>"
                  /><%
            }).Title("Picture");
            columns.Bound(c => c.ContactName).Title("Name");
            columns.Bound(c => c.Phone);
        })
        .Sortable()
        .Scrollable(scrolling => scrolling.Height(250))
        .Pageable()
        .Render();
 %>

As you can see template columns need <% instead of <%= and also the Render() method should be called. This was outlined in the help topic which I send you in my first reply.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Li Billy
Top achievements
Rank 1
answered on 05 Mar 2010, 05:31 PM
The problem before is fixed but it brought to a new problem. It has the following Error Message:

Cannot use templates in Ajax or WebService binding mode

...@@
0
Atanas Korchev
Telerik team
answered on 05 Mar 2010, 05:34 PM
Hello Li Billy,

Please check this help topic (the section "The grid does not support templates and client-side binding (Ajax, WebService").

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Li Billy
Top achievements
Rank 1
answered on 05 Mar 2010, 05:46 PM
Bingo!!! I have finally got the answer. Thank YOU!!!

Just a minor point:

             columns.Add(c => c.CustomerID)
.Format(Html.ActionLink("Edit", "Home", new { id = "{0}"}}))
.Encoded(false)
.Title("Edit");

it seems the trouble shooting you provided has an extra "}", you may verify it. I removed that and my program works ^__^
0
Li Billy
Top achievements
Rank 1
answered on 05 Mar 2010, 06:15 PM
Oh, sorry to bother, but the problem is

            columns.Add(c => c.CourseId)
                    .Format(Html.ActionLink("Edit Course Details", "Edit", new { controller = "Course", courseId = c.CourseId }))
                    .Encoded(false)
                    .Title("Edit");

I can't pass the object value(ie, courseId = c.CourseId) to the ActionLink.
It says:

Error    1    The name 'c' does not exist in the current context   

Is there any solution on this?



0
Atanas Korchev
Telerik team
answered on 08 Mar 2010, 08:12 AM
Hello Li Billy,

You need to use "{0}" when using Format.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Li Billy
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Li Billy
Top achievements
Rank 1
Share this question
or