tags:

views:

80

answers:

2

In our old system we had pages rendered from XSLT. In order to change the page into "edit" mode we would have a button of some sort, once clicked would have an EditYN flag which would be passed to the stored procedure. The stored procedure would simply give this variable back to indicate that the page was in edit mode. This meant that query strings, viewstate or session data were not required to indicate that the page is in edit mode.

I've been dealing with ASP.NET MVC only for the last week for RND purposes at work. I'm wondering what's the best way to have a page which displays data, to then turn into a page where you can edit all of that data? Should you move to a separate page? Should you stay on the same page and have rendering logic in the view to show the edit mode of the page?

Whilst on the same topic, I thought I'd also ask about GridViews and their place in the MVC architecture. Beforehand we'd simply use data sources and set them up with the GridView. Then the GridView could enter edit mode quite easily by itself with the UPDATE query set in the data source. How should this process be done using MVC?

+2  A: 

Make a submit button for your edit mode. The controller action will respond to POST, set the "InEdit" flag in your model, then return the same view again. The view can then render based on the flag. But I would rather create two different views, for view and edit modes, then based on the flag analysis done in the controller action just return the one or the other view.

User
It's good to know someone else would make two different views. This is usually frowned upon at my work, but I never saw it as a bad thing.
Kezzer
In my work we also have lots of pages that change themselves dependent on some conditions. I know how hard it is to deal with those conditions in rendering logic. Lately there has been some understanding that it is better to create a separate page (view) than to add switching conditions to it.
User
A: 

Whilst on the same topic, I thought I'd also ask about GridViews and their place in the MVC architecture. How should this process be done using MVC?

You can use javascript, something like jqGrid or Yahoo´s datatable. For simpler datatables, you can use jQuery´s tablesorter.

On the backend, your controller returns json objects that can be modified by the client, ie. the javascript grid which then sends the data back to the controller to be saved.

Morph
So does this reinforce the fact that GridView's should not be used?
Kezzer
The asp.net gridview ? That's a serverside control, and you cannot use serverside controls with asp.net mvc.
Morph
@Morph: So our only option is to manually render elements on the page?
Kezzer
You'll have to put some sort of code and text in the view yes. You can use the build in codegeneration to get you on your way. There are also different viewengines, but I'd first start with the basics before diving into that.Just watch some of the tutorials out there, that's probably the best way to get started.
Morph