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

Template column in mvc gridview

8 Answers 465 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Atul Srivastav
Top achievements
Rank 1
Atul Srivastav asked on 13 Oct 2010, 04:51 PM
Hi,

I am working in MVC 1.0. I am using "Telerik Extensions for ASP.NET MVC Q2 2010". I want to use hiperlink in template column.
I take this code for template column from "Extensions for ASP.NET MVC Q2 2010 Documentation" chm,
But after adding template column this page is throwing error and I am not able to understand error point. Please help me in this.

Regards
Atul Kumar Srivastav

<%= Html.Telerik().Grid<Hotel>()
        .Name("Hotels")
        .BindTo((IEnumerable<Hotel>)ViewData["Hotels"])
        .Columns(columns =>
        {
            columns.Bound(o => o.Name).Title("Hotel");
            columns.Bound(o => o.Port).Title("Port");
            columns.Bound(o => o.ContactListString).Title("Contacts");
            columns.Bound(o => o.FaxNumber).Title("Fax number for voucher");
            columns.Template(o =>
              {
                
                  %>
                  <%= Html.ActionLink("Edit", "Home", new { id = o.Name }) %>
              <%

                
              })




        })
        .Pageable()
        .Sortable()

    %>

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Oct 2010, 07:12 AM
Hi Atul Srivastav,

 This is the recommended approach of adding a template column and is supposed to work. You forgot to mention what the exception was. I suggest you attach a sample project.

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
Atul Srivastav
Top achievements
Rank 1
answered on 14 Oct 2010, 10:57 AM
Hi Atanas Korchev

I have attached my test application. In this project on "\MovieApp\MovieApp\Views\Home\Index.aspx" I have put my code for template column which have same problem. Please let me know where I am wrong.

Regards
Atul Kumar Srivastav
0
Atanas Korchev
Telerik team
answered on 14 Oct 2010, 01:24 PM
Hi Atul Srivastav,

 The problem is that you must use the Render() method when working with server templates:

    <% Html.Telerik().Grid(Model)
        .Name("MovieSet")
        .Pageable()
        .Sortable()
        .Columns(columns =>
        {
            columns.Bound(o => o.Id).Title("ID");
            columns.Bound(o => o.Title).Title("Title");
            columns.Bound(o => o.Director).Title("Director");
            columns.Bound(o => o.DateReleased).Title("Date Released");
            //Template column which shows an action link
            columns.Template(o =>
            {
            %>
              <%= Html.ActionLink("Edit", "Home", new { id = o.Id })%>
            <%
            
        }).Title("Edit");
        })
        .Render();
    %>

Also instead of <%= you must use <%.

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
Atul Srivastav
Top achievements
Rank 1
answered on 14 Oct 2010, 05:39 PM
Hi Atanas Korchev

Thanks your previous mail work and I am able to get ahead.  but now I got problem with grid Edit command column.
I have again added it in my test application. Please help me again

Regards
Atul Kumar Srivastav

<% Html.Telerik().Grid(Model)
        .Name("MovieSet")
        .Pageable()
        .Sortable()
        .DataKeys(keys => keys.Add(c => c.Id))
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
        .DataBinding(dataBinding => dataBinding.Server()
              .Select("EditingServerSide", "Grid", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
              .Insert("Insert", "Grid", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
              .Update("Save", "Grid", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
            )
        .Columns(columns =>
        {
            columns.Bound(o => o.Id).Title("ID");
            columns.Bound(o => o.Title).Title("Title");
            columns.Bound(o => o.Director).Title("Director");
            columns.Bound(o => o.DateReleased).Title("Date Released");
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.ImageAndText);
            }).Width(180).Title("Commands");
            //Template column which shows an action link
            columns.Template(o =>
            {
            %>
              <%= Html.ActionLink("Edit", "Home", new { id = o.Id })%>
            <%
             
        }).Title("Edit");
        })
        .Render();
    %>

0
Rosen
Telerik team
answered on 15 Oct 2010, 08:01 AM
Hello Atul,

Unfortunately, as stated here, editing functionality is not available for ASP.NET MVC 1.

Kind regards,
Rosen
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
Atul Srivastav
Top achievements
Rank 1
answered on 22 Nov 2010, 06:19 PM
Hi

I updated my project in mvc2 and now I am using "Telerik Extensions for ASP.NET MVC Q3 2010" dll for my project.
Now I want server side edit on /home/index.aspx my aspx code is this
<% Html.Telerik().Grid(Model)
       .Name("MovieSet")
       .Pageable()
       .Sortable()
       .DataKeys(keys => keys.Add(c => c.Id))
       .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
       .DataBinding(dataBinding => dataBinding.Server()
             .Select("EditingServerSide", "Home", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
             .Insert("Insert", "Home", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
             .Update("Save", "Home", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
             .Update("Delete", "Home", new { mode = GridEditMode.PopUp, type = GridButtonType.Text })
           )
       .Columns(columns =>
       {
           columns.Bound(o => o.Id).Title("ID");
           columns.Bound(o => o.Title).Title("Title");
           columns.Bound(o => o.Director).Title("Director");
           columns.Bound(o => o.DateReleased).Title("Date Released");
           columns.Command(commands =>
           {
               commands.Edit().ButtonType(GridButtonType.ImageAndText);
           }).Width(180).Title("Commands");
            
            
        
       })
       .Render();
   %>

and for I have added this code in HomeController

public ActionResult EditingServerSide()
{
    return View(_db.MovieSet.ToList());
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingServerSide(int i)
{
    return View(_db.MovieSet.ToList());
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save(int id)
{
    return View(_db.MovieSet.ToList());
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Insert(int id)
{
    return View(_db.MovieSet.ToList());
}
 
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int id)
{
    return View(_db.MovieSet.ToList());
}

But while I was clicking on edit button this code is throwing error.

The view 'EditingServerSide' or its master was not found. The following locations were searched:
~/Views/Home/EditingServerSide.aspx
~/Views/Home/EditingServerSide.ascx
~/Views/Shared/EditingServerSide.aspx
~/Views/Shared/EditingServerSide.ascx



Please help me to solve this. I am attaching my test project for this

Regards
Atul Kumar Srivastav
0
Rosen
Telerik team
answered on 23 Nov 2010, 08:25 AM
Atul,

The error your getting is due to the fact that when no View name is specified when using the Controller's View method, the View which will be loaded by MVC framework is with the name of the action itself. Therefore, in your case a call to EditingServerSide action will result in executing an EditingServerSide View which dies not exists. In order to correct the behavior you should use the overload of the VIew method which explicitly states the View name.

public ActionResult EditingServerSide()
{
    return View("Index", _db.MovieSet.ToList());
}


All the best,
Rosen
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
Dan
Top achievements
Rank 1
answered on 21 Jan 2011, 07:28 PM
I have a template column that can sort and filter but I can not clear the filter . Is there a problem with the grid?
Here is the column code. I just need to clear the filter.

c.Bound(o => o.ACCT_NM)

.ClientTemplate(

 

"<a href='../Account/LogOn' type='text/plain'><#= ACCT_NUM #></a>")

 

.Template(o =>

{

%>

<%

 

= Html.ActionLink(o.ACCT_NUM, "LogOn", "Account") %>

 

<%

 

}).Title(

 

"Acct Num 2").Filterable(true);

 



Tags
Menu
Asked by
Atul Srivastav
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Atul Srivastav
Top achievements
Rank 1
Rosen
Telerik team
Dan
Top achievements
Rank 1
Share this question
or