Alex Rivera | Logout

Use MVCContrib grid for editing

Asked 2009-05-05T23:32:09.700
12

I just started using the MVCContrib grid in a test project. I'm having a difficult time finding information on how to use it for edit/update/delete.

Can anyone point me to information on how to put a row into edit mode, or if there isn't such a thing for that grid, discuss a best practice for editing list data in MVC.

Edit
Report

1 Answer

10

It appears as if MVCContrib is a simple way to construct the HTML Table from a collection of model objects. It doesn't appear as if has any ability to put a row into edit/update/delete "mode" similar to the WebForms GridView.

However, it does look like you can handle that functionality however you want to. If you want to go to a separate page for edit mode, just put a link in one of the columns with that row's id. The following is taken directly from: http://www.jeremyskinner.co.uk/2009/03/01/mvccontrib-grid-part-5-the-action-syntax/

<% Html.Grid(Model).Columns(column => {
            column.For(x => x.Id).Named("Person ID");
            column.For(x => x.Name);
            column.For(x => x.Gender);
            column.For(x => x.DateOfBirth);
                column.For("View Person").Named("").Action(p => { %>
                     <td style="font-weight:bold">
                    <%= Html.ActionLink("View Person", "Show", new { id = p.Id })%>
                 </td>
                <% });
        }).RowStart((p,row)  => {     
             if (row.IsAlternate) { %>
                   <tr style="background-color:#CCDDCC">
             <%  }  else  { %>
                 <tr>
             <% }
    }).Render(); %>

Here it looks like they are wanting to direct the user to a View Person page: <%= Html.ActionLink("View Person", "Show", new { id = p.Id })%>.

Good luck, and happy coding.

answered 2009-05-06T00:18:11.977

Your Answer