Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

with mvc.net is it possible to share a view between multiple actions

Tags:

asp.net-mvc

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?

like image 978
yamspog Avatar asked Sep 02 '10 20:09

yamspog


1 Answers

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");
}
like image 68
Mark Avatar answered Sep 19 '22 08:09

Mark