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

Kendo Button in Kendo Grid (MVC)

3 Answers 292 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary Davis
Top achievements
Rank 2
Gary Davis asked on 12 Nov 2014, 01:35 AM
Hello,

As you can see, I've made several attempts to create a Command column that routes a certain way (to /orderdetails?orderid=xxx).  The first 2 columns do create an ActionLink, but I'm looking for a button.  So on the 3rd non-commented column, it does work, but it uses "CartObject.CartSubObject.Property" (which it is getting from the Model, I assume) as the parameter in the Querystring.  How can I change this to a pre-defined property like "orderId"?

This is for an ASP.NET MVC 4 application using .NET 4.5.1.

[code]
Html.Kendo().Grid(Model.Orders)
    .Columns(columns =>
    {
        columns.Template(c => @Html.ActionLink("View", "orderdetails", new { orderId = c.CartId }))
            //.HtmlAttributes(new { @class = "k-button", @style = "white" })
            .Title("View")
            .Width(90);
        //columns.Command(c => @Html.ActionLink("account", "orderdetails", new { orderId = c..CartId })).Title("View").Width(90);
        columns.Bound(m => m.CartId).Template(c => Html.ActionLink("View", "orderdetails", new { id = c.CartId })).Title("Actions")
            .ClientTemplate(Html.ActionLink("View", "orderdetails", new { orderId = "id" }).ToHtmlString().Replace("id", "#=CartId#")).Title("Actions");
        columns.Command(com => com.Custom("View").Action("orderdetails", "account")).Title("Actions").Width(90);
        //columns.Command(com => com.Custom("View").Action("orderdetails", "account", new { orderId = "id" })).Title("Actions").Width(90);
        //columns.Bound(o => o.CartId).ClientTemplate(@Html.ActionLink("orderdetails", "account", new { orderId = "#=CartId#" }).ToHtmlString());
        //columns.Command(command => command.Custom("View")
        //    .Click("showDetails"))
        //    .Title("Actions").Width(90);
        columns.Bound(c => c.CartId)
           .ClientTemplate
              (@Html.ActionLink
                  ("<span class='k-icon k-edit'></span>View",
                   "orderdetails",
                   new { id = "#=CartId#" },
                   new { @class = "k-button k-button-icontext" }).ToHtmlString());
    })
    .HtmlAttributes(new { style = "max-width: 750px" })
    .DataSource(dataSource => dataSource
        .Server()
        .Model(model => model.Id(o => o.Cart.CartHead.CartID))
        .Sort(s => s.Add(a => a.Cart.CartHead.DateSubmitted).Descending())
        .PageSize(25)
    )
    .Sortable()
    .Name("OrderHistoryGrid")
    .Pageable(pageable => pageable
        .Enabled(Model.Orders.Any())
        .Numeric(true)
        .PreviousNext(true)
        .Refresh(true)
        .PageSizes(new int[] { 25, 50, 100 })
        .ButtonCount(10)
        .Messages(m => m.Empty("There are currently no orders affiliated with this account"))
    )
    .Render();
[/code]

3 Answers, 1 is accepted

Sort by
0
Gary Davis
Top achievements
Rank 2
answered on 12 Nov 2014, 07:16 PM
I found this post:
http://stackoverflow.com/questions/7958056/telerik-asp-net-mvc-grid-adding-custom-delete-button

It had this type of column, but it did not work for me.  It did not recognize "o" in DataRouteValues.

colums.Command(commands => commands
.Custom("Edit")
.Text("Edit")
.SendState(false)
.DataRouteValues(route =>
{
route.Add(o => o.EmployeeID).RouteKey("orderID");
})
.Ajax(true)
.Action("actionresult", "mycontroller"));
0
Gary Davis
Top achievements
Rank 2
answered on 12 Nov 2014, 07:34 PM
I was able to get this to partially work, but it still adds an additional parameter on the Querystring:

columns.Command(commands => commands.Custom("Edit").Text("View1").SendState(false)
           .DataRouteValues(route =>
           {
               route.Add(o => o.CartId).RouteKey("orderId");
           })
           .Action("orderdetails", "account"));
0
Accepted
Dimo
Telerik team
answered on 13 Nov 2014, 04:43 PM
Hello Gary,

The model ID value of the table row is added as a query string parameter by default, so you don't need to add it twice. In other words, you can completely remove the .DataRouteValues() method.

In case you want to send CartId value with a query string parameter with a different name ("orderId"), I am afraid this is not possible.

Regards,
Dimo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Gary Davis
Top achievements
Rank 2
Answers by
Gary Davis
Top achievements
Rank 2
Dimo
Telerik team
Share this question
or