0

I'm new to MVC, and I'm having a hard time with a task that would be pretty easy with classic ASP.net.

I have a gridView that has a checkbox in each row, and I want a functionality where the user ticks the checkboxes of the rows he wants, clicks some button on the page and the selected rows would be sent to the server.

In normal ASP, the whole page is sent so its easy to check the gridView rows and the checkbox in each row, but in MVC the whole point is the Controller class not knowing about the details of the GUI, so how do I implement such a thing in MVC?

tereško
  • 58,060
  • 25
  • 98
  • 150
Avi Sasson
  • 666
  • 7
  • 22

1 Answers1

0

You don't use server-side controls like that in MVC. GridView is for web forms framework. These two SO posts cover similar issues:

  1. grid controls for ASP.NET MVC?
  2. How to use gridView in Mvc without adding form runat server?

So there are a lot of examples in that post. I've used jQuery DataTables without issues. You build your table with a loop and then apply the DataTable to turn it into a searchable, sortable, filterable grid.

Walking through a tutorial, like the one at http://www.asp.net/mvc will get you familiar with how MVC works and show you how to update your models.

Update: I have no idea how your back-end is configured, so this is a shot-in-the-dark... but one easy way to get started is like this:

  1. Once you have your model, go to your Controllers folder and right click -> Add -> Controller
  2. Name it
  3. Under Template choose "MVC controller with read/write actions and views, using Entity Framework"
  4. Choose your model class
  5. Choose your data context
  6. Click Add

This will create a controller with all your CRUD operations and the related views. Poking around that should help... especially the Edit.cshtml.

Community
  • 1
  • 1
MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89
  • Thanks! But I still need some way to implement what I described - I need some way to send the rows (or at least the id field of each row) that were ticked to the server. Is there any way to do this in MVC? – Avi Sasson Feb 08 '13 at 22:57
  • Yes, but that is a big question, and unfortunately pointing you in the right direction seems like the only practical way to answer your question. Spend a few hours and go through that tutorial and you will see how to build, view, and update your models. When you run into a specific problem, come back to SO and ask a specific question with your code and the problems you are having :) – MikeSmithDev Feb 08 '13 at 22:58
  • I think its a pretty specific question. I'm not asking for the whole source code, just a way of achieving this. Suppose I built the site and handled the data, I have a table with a checkbox in each row - my question is how do I get the state of each of these checkboxes in the controller? – Avi Sasson Feb 08 '13 at 23:02
  • @AviSasson I updated my answer... hopefully that works for you and gets you started. – MikeSmithDev Feb 08 '13 at 23:31
  • Ok, thanks! Sorry of I came through as a lazy programmer, I've spent some time reading a PDF tutorial on how to build MVC applications, now I have a better understanding of things – Avi Sasson Feb 09 '13 at 08:33