tags:

views:

33

answers:

3

This is a noob question, but I will ask it anyway...

I'm wanting to create a page that will do basic CRUD operations on a list of items: -display the list -edit an item -create an item -delete an item

It is looking like I will need an action for each of this operations. This is good and understandable. My question is regarding the views for interacting with the user.

I want to have in-place editing, so the user clicks on edit and they can edit the details of the item in the list. In my current understanding, i will have to duplicate a great deal of the view between 'display the list' and 'edit an item'. however, this seems to be unnecessary redundancy and will make future updates more time-consuming as I will have to update each view.

Is there an easier way? Am I on the right/wrong track? Any other comments?

A: 

I can't post comments yet, but I will try to answer.

I believe what you should be looking into is rendering partial views, which are .ascx pages similar to UserControls in WebForms. They're basically shared partial views that you can use for the same purposes across many views.

If you look in the default project template you can find examples for items such as the Login control.

Edit: And as others have noted, you can also share views between actions. Had my own noob moment there too. :)

Delebrin
+1  A: 

The View() method can take the name of a view as a parameter, so you can render the same view from several actions. By default (if you don't specify a view name) the framework uses a view named as the current action. See here for details.

M4N
+3  A: 

Yes, absolutely. You'll want to use the overload of View() that takes a string. The string is the name of the view to render:

public ActionResult MyAction()
{
    return View("MyViewName");
}
Mark