views:

641

answers:

2

I am considering creating a view that allows for ajax-based search and edit functions. I would appreciate any feedback on the structure I am considering!

The structure will consist of A textbox and a search button Submit of the button causes the action Search to be hit, and a partial is returned with - text representation of items found in a named div "itemDisplay##" (## being the Id of the item found) - button named edit - placeholder div with the id of the found item "itemEdit##" When a user hits the edit button, a partial view (Edit.ascx) is requested and fills the named div itemEdit## Edit.ascx has Save and Cancel buttons.

Successful Save and cancel hide the edit div and displays the original itemDisplay## Failure during a save is displayed in the edit.ascx.

+2  A: 

These all sound like discrete actions and thus not particularly RESTful in it's implementation. Typically I will have a List action with filtering -- this filtering could be done via AJAX since what it is returning is basically the same view. Clicking on a particular item might bring me to a details view -- with an edit button. I might also include an edit button in the list, in which case clicking it would bring me to an details page in edit mode. List, View, and Edit would all be different actions, though, and have different URLs. Clicking the list button in View or Edit would return me to the List action. Clicking the save button in Edit would return me to the View for that item -- this provides confirmation that the item has been updated. Errors in Edit render the edit view with appropriate messages.

My rule of thumb is to use AJAX when the context of the view isn't changing, but a full request (GET/POST) when a new action (new context) is invoked. This helps to keep the interface (URLs) RESTful. Of course, you can do it any way you want, but MVC makes doing RESTful URLs easier and RESTful URLs make it easier for the user to bookmark a page to get back to it easily -- precisely because they map to a particular action on a particular data item.

tvanfosson
A: 

The searching can be done in an 'ajax way' as you describe. Using the same url / page for editing and showing details will clutter up the code though, and as stated in another answer isn't very restfull, so I would use seperate URLs and pages for that.

Morph