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

[Solved] Implementing the Checkboxes in Telerik Grid with View Model

5 Answers 73 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.
Vishnu
Top achievements
Rank 1
Vishnu asked on 06 Feb 2012, 06:06 PM

Hi Experts & friends,

This is my first project with Telerik MVC. I have searched the Examples, Demos, blogs and this forum before posting here. I am in desparate need of a solution. Please help.

I have a view model which has a List object. This List object is used to bind to the Telerik grid. In the Telerik grid, I have used Template Column to display the checkbox. The user can change the checkbox value for one or more rows. Based on the selection, the controller has to do some operation. The objective is to find the rows where the checkbox value is modified.

Problem:

1. After Save button click (Post operation), the View Model parameter shows NULL for the CustomerList Object.

2. Alternatively, as explained in the Demos, I have included a variable int[ ] IsSelected = new int[ ] { }; This array gets me all the records where checkbox is selected. But, I need only the records where the checkbox value is changed. Another problem in this approach, which I don's mind though is, it does not get me the record if the checkbox is checked but disabled.
http://demos.telerik.com/aspnet-mvc/grid/checkboxesserverside

3. When I was not using the Telerik grid, I used a alternate approach which was explained here. i.e. The name attribute is set in a way where it will render like name="CustomerList[0].ID"
http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx

Model:

Class CustomerViewModel
{
    public string CustomProperty1 {get; set;}
    public string CustomProperty2 {get; set;}
    public List<Customer> CustomerList {get; set;}
}
  
Class Customer
{
    public int ID {get; set;}
    public string Name {get; set;}
    public bool IsBlacklisted {get; set;}
    public bool IsSelected {get; set;}
}


Controller:

public ActionResult Index()
{
    CustomerViewModel basket = PopulateViewModel(); // viewModel built here
    return View(basket); // viewModel is bind to the grid
}
  
[HttpPost]
public ActionResult Save(CustomerViewModel viewModel, int[] IsSelected)
{
    // viewModel.CustomerList - This object is NULL
    // IsSelected - This gives the rows where checkboxes are Checked, but I look 4 only the modified
}

View:

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<ViewModels.CustomerViewModel>" %> 

<form id="CustomerGridForm" action="/Customer/Save" method="post">

 

<%

int [] IsSelected = new int[] { };
Html.Telerik().Grid(Model.CustomerList)

 .Name("CustomerGrid")

.Columns(columns =>
{
    columns.Bound(o => o.ID);
    columns.Bound(o => o.Name);
    columns.Template(o =>
    { %>  
    <input name="IsSelected" type="checkbox" title="IsSelected" value=" <%= o.ID %>"
  
    <%if (o.IsSelected)
    {%>
        checked="checked" <%
    %>
  
    <%if (o.IsBlacklisted)
    {%>
        disabled="disabled" <%
    }%>
     />
    });
}).Render();

<button type="submit" class="t-button" value="Save" name="Save">Save</button>

 

</form>

 

5 Answers, 1 is accepted

Sort by
0
Vishnu
Top achievements
Rank 1
answered on 13 Feb 2012, 05:58 AM
Hello Telerik Team,

Disappointed that no replies or any suggestion from the Telerik team. Does it need to be requested through Support rather than forums?

Regards,
Vishnu
0
Atanas Korchev
Telerik team
answered on 13 Feb 2012, 09:33 AM
Hi,

 Telerik does not guarantee replies to forum posts. If you need a guaranteed response you may consider opening a support ticket.

 As for this problem I am not sure it is caused by Telerik Grid for ASP.NET MVC. You can try implementing your requirement without the grid first (you can use a table for example). Once it is working you can plug in the grid.

Regards,
Atanas Korchev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Vishnu
Top achievements
Rank 1
answered on 13 Feb 2012, 10:30 AM
Hi,

Thanks for the response.

Before purchasing Teleirk, I have implemented this using generic table. You can refer my 3rd point on how it was implemented. But, when I use Telerik grid, I could not do this.

3. When I was not using the Telerik grid, I used a alternate approach which was explained here. i.e. The name attribute is set in a way where it will render like name="CustomerList[0].ID"
http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx

Regards,
Vishnu
0
Atanas Korchev
Telerik team
answered on 13 Feb 2012, 10:39 AM
Hi,

Could you tell us why you cannot do this with the grid? What were the problems? Can you send us the project which works as expected with a table?

On a side note your account is not currently listed as having a valid purchase. If you have made the purchase using a different account you can use that account instead to open support tickets. If someone else made the purchase you may ask him or her to add you as a licensed developer.

Regards,
Atanas Korchev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Vishnu
Top achievements
Rank 1
answered on 13 Feb 2012, 11:06 AM
Hi,

Thanks for the suggestion. I will try to get my name added as a licensed developer.

I will send a sample project on how it worked in non-telerik table.

Regards,
Vishnu
Tags
Grid
Asked by
Vishnu
Top achievements
Rank 1
Answers by
Vishnu
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or