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

[Solved] Custom command button

4 Answers 325 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.
Datamex
Top achievements
Rank 2
Datamex asked on 28 Mar 2011, 03:23 PM
In the mvc grid, is is possible to create an extra command button to do a custom action? I'd like to add a button 'Edit' which doesn't edit inline (like the default command), but redirects the user to another view in which an edit form is shown.

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 28 Mar 2011, 04:14 PM
Hello Datamex,

In order to achieve the desired functionality, you may use a template column which contains a link.

client template:

columns.Bound(c => c.CustomerID)
.ClientTemplate(Html.ActionLink("Click Me", "Edit", "Customer", new { CustomerID = "<#= CustomerID #>" }, null).ToHtmlString());

server template:
columns.Bound(c => c.CustomerID).Template(c => {
     %>
     <%=Html.ActionLink("Click Me", "Edit", "Customer", new { c.CustomerID }, null)%>
     <%
 })

More information about column templates can be found in our help documentation.


All the best,
Rosen
the Telerik team
0
Datamex
Top achievements
Rank 2
answered on 28 Mar 2011, 04:15 PM
Thanks, but that would render a link right, not a button?
0
Rosen
Telerik team
answered on 29 Mar 2011, 07:46 AM
Hi Datamex,

Generally speaking the button html element will do a post request, thus a form element will be needed or you will need to handle the click event through javascript and navigate to the new page manually. Therefore, the easiest way to do a GET request and have a button like look is to style the anchor html element. You can take a look at such approach in this demo for example, where the select button is an anchor element to which is applied t-button css class, thus it is styled to look like a button.

Regards,
Rosen
the Telerik team
0
Datamex
Top achievements
Rank 2
answered on 29 Mar 2011, 08:25 AM
Hmmm, I will try that. This is the kind of the reason why I'm still not so sure about MVC. Trivial things like this, just putting a button inside a grid, seem to be a lot harder then they are in just regular ASP.NET. Is it me not understanding the technique, or is it just the way MVC rolls...
Tags
Grid
Asked by
Datamex
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Datamex
Top achievements
Rank 2
Share this question
or