views:

22

answers:

1

This may be an easy question, but if it is one i haven't found a solution. I have a view model that is updated when a button is pressed, and on the update an IList within it will be given some results (this i know works). However i am trying to bind this Ilist to a gridview within the view page. Every time i try to assign a datasource or datasourceid, firstly my resharper is hostile towards it saying it should be removed, but when i try to run it crashes on load. Does anyone have any insight on how to proceed?

+2  A: 

You shouldn't be using server controls like GridView in an ASP.NET MVC application. Those controls rely on ViewState and PostBack models which are a no-no in MVC. There's no notion of data binding either. Your controller is passing a view model to the view (a list in this case) and the view has to render it. There is a nice HTML helper in MVCContrib.Grid which you could use to display data in a table. It also supports paging and sorting. If you don't want to use third party helper methods you could loop through the model in your view and manually generate the <tr> and <td> but this could be a tedious task. So yes, back to the basics, back to the real world wide web. No longer leaky abstractions such as WebForms.

So to conclude: in an ASP.NET MVC view <asp:XXX runat="server" ... /> are forbidden. Simply remove them from the views. I would also recommend you going through the tutorials here.

Darin Dimitrov
I figured that asp.xxx was a no-go really. I was essentially hoping that since i only required the display portion of the gridview that it would still be usable. Call it wishful thinking i guess.
John Stuart