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

[Solved] Error using Ajax.ActionLink as column on MVC Grid ...

8 Answers 241 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.
IQworks
Top achievements
Rank 1
IQworks asked on 02 Mar 2010, 04:14 AM
Hi,
    I have a grid that works fine with HTML.ActionLink ....
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<BCAnalytics.Models.CompanyVM>>" %> 
<%if (false)  
  {%> 
  <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script> 
 <% }%>    
   
   <p><%= Html.ActionLink((String)Resources.BCAResources.stdClose, "Index", "Work", new { workindex = 0 }, null)%></p>   
    
        <%= Html.Telerik().Grid(Model)  
              .Name("CompanyGrid")  
              .Columns(columns => 
                {  
                    // columns.Add(o => o.cMemberNo).Width(30);  
                    // columns.Add(o => o.cCompanyNo).Width(30);  
                    columns.Add(o => o.cCompanyName).Width(175).Title((string)Resources.BCAResources.coxCompany)  
                       .HtmlAttributes(ID="cname");  
                         
                    columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75);  
                    columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100);  
                    columns.Add(o => o.cEmail).Width(120).Title((string)Resources.BCAResources.stdEmail).Width(150);  
                    columns.Add(o => o.cDateUpdated).Format("{0:MM/dd/yyyy}").Width(85).Title((string)Resources.BCAResources.stdUpdated);  
                    columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdEdit, "Index", "Work", new { workindex = 2OtherParms = "{0}" }, null).ToString()).Encoded(false).Title("").Width(32);  
                    columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdDelete, "CompanyDelete", new { Id = "{0}" }, null).ToString()).Encoded(false).Title("").Width(50);  
                })  
               .Ajax(settings => settings.Action("_AjaxBindingCompany", "Company"))  
               .Pageable()  
               .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn))  
               .Scrollable(scrolling => scrolling.Height(200))  
               .Filterable()  
               %> 
   
 <p><%= Html.ActionLink((String)Resources.BCAResources.coxFormEntry, "Index", "Work", new { workindex = 2OtherParms = "Create" }, null)%></p>     
    
   
 

    But when I try to use AJAX.ActionLink, I get the error "

Input string was not in a correct format.  
   
I have tried several variations of this line of code, wont list them all here, but this is the latest one I have tried. 

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<BCAnalytics.Models.CompanyVM>>" %> 
   <p><%= Html.ActionLink((String)Resources.BCAResources.stdClose, "Index", "Work", new { workindex = 0 }, null)%></p>   
      <div id="CompanyGridr">  
        <%= Html.Telerik().Grid(Model)  
              .Name("CompanyGrid")  
              .Columns(columns => 
                {  
                     columns.Add(o => o.cMemberNo).Width(30) ;  
                    columns.Add(o => o.cCompanyNo).Width(30);  
                    columns.Add(o => o.cCompanyName).Width(175).Title((string)Resources.BCAResources.coxCompany);  
                    columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75);  
                    columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100);  
                    columns.Add(o => o.cEmail).Width(120).Title((string)Resources.BCAResources.stdEmail).Width(150);  
                    columns.Add(o => o.cDateUpdated).Format("{0:MM/dd/yyyy}").Width(85).Title((string)Resources.BCAResources.stdUpdated);  
                    columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdEdit, "Index", "Work", new { workindex = 3OtherParms = "{0}" }, null).ToString()).Encoded(false).Title("").Width(32);  
                    columns.Add(o => o.cCompanyNo).Format(Ajax.ActionLink("Del", "CompanyDelete", new { Id = "{0}" }.ToString(), new AjaxOptions() { UpdateTargetId = "CompanyGridr" })).Encoded(false).Title("").Width(50);  
 
                })  
               .Ajax(settings => settings.Action("_AjaxBindingCompany", "Company"))  
               .Pageable()  
               .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn))  
               .Scrollable(scrolling => scrolling.Height(200))  
               .Filterable() %>     
       </div>                 
       <p><%= Html.ActionLink((String)Resources.BCAResources.coxFormEntry, "Index", "Work", new { workindex = 2OtherParms = "" }, null)%></p>   
        

    this is the error .... 
Server Error in '/' Application.  
--------------------------------------------------------------------------------  
 
Input string was not in a correct format.   
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.   
 
Exception Details: System.FormatException: Input string was not in a correct format.  
 
Source Error:   
 

    I tried to find some examples of this, but the ones I found working with Telerik MVC Grids did not seem to work. I know I am not seeing something ? 

  thanks for your time.

8 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 02 Mar 2010, 09:31 AM
Hello IQworks,

This is because Ajax.ActionLink outputs  "{" and "}" which are then treated as format parameters. To fix this problem try this:
Ajax.ActionLink("Del", "CompanyDelete", new { Id = "{0}" }, new AjaxOptions() { UpdateTargetId = "CompanyGridr" }).ToString().Replace("{", "{{").Replace("}", "}}")

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
IQworks
Top achievements
Rank 1
answered on 02 Mar 2010, 05:25 PM
  Thanks again Atanas, that worked great ! 
  i guess I should of been searching for this error under Ajax.  
  For others, my final code was this ..... 
   

columns.Add(o => o.cCompanyNo).Format(Ajax.ActionLink(

"Del", "CompanyDelete", new { Id = "{0}" },

 

 

new AjaxOptions() { UpdateTargetId = "CompanyGridr"}).ToString().Replace("{", "{{").Replace("}", "}}")).Encoded(false).Title("").Width(50);

 

 

 

 

     
       

0
Jose Granja
Top achievements
Rank 1
answered on 12 Mar 2010, 03:04 PM
Hi, I have a similar problem.

I want to format this way:

columns.Add(o => o.DateEmailed).Format(DateConverter.FormatDate("{0}");

even is I put DateConverter.FormatString("{0}") the param passed to the function is "{0}" and not the Date! How can I solve that?
0
Atanas Korchev
Telerik team
answered on 12 Mar 2010, 03:16 PM
Hi IQworks,

The Format method accepts a string specifying the format of the column. That format is later used internally to format the data. Check the columns help topic for additional info.

If you want to manipulate the actual date you use the Template method.

All the best,
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
Jose Granja
Top achievements
Rank 1
answered on 12 Mar 2010, 03:21 PM
is it from the new version de template method??? I'm not using it at the moment.

I only have the add method:

.Columns(columns =>
        {
            columns.Add(o => o.ID).Width(60);
            columns.Add(o => o.PrimaryName.Forename).Width(220);
            columns.Add(o => o.PrimaryName.Surname);
            columns.Add(o => o.PrimaryAddress.Postcode);
            columns.Add(o => o.DateOfBirth); etc
0
Jose Granja
Top achievements
Rank 1
answered on 12 Mar 2010, 03:23 PM
I get this error:

Compiler Error Message: CS1061:'Telerik.Web.Mvc.UI.GridColumnFactory<EmmaConsultant.Models.POA.Patient>'does not contain a definition for 'Template' and no extension method'Template' accepting a first argument of type'Telerik.Web.Mvc.UI.GridColumnFactory<EmmaConsultant.Models.POA.Patient>'could be found (are you missing a using directive or an assemblyreference?)
0
Jose Granja
Top achievements
Rank 1
answered on 12 Mar 2010, 03:25 PM
I tried this way:

columns.Add(o => 
              {
                  %>
                      <%= DateHelper.ToStringFormat(DateTime.Now) %>
                  <%
              }).Title("Edit");

but I get: 

Cannot use templates in Ajax or WebService binding mode

Description: Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details: System.NotSupportedException: Cannot use templates in Ajax or WebService binding mode
0
Atanas Korchev
Telerik team
answered on 12 Mar 2010, 03:25 PM
Hello Jose Granja,

Yes, the Template method is introduced with the 2010.1.* release. However I was not talking about it. Please check the help article linked in my previous reply. It explains what the Format method does and how to set the template for server binding.

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
IQworks
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
IQworks
Top achievements
Rank 1
Jose Granja
Top achievements
Rank 1
Share this question
or