views:

227

answers:

4

I am currently using asp.NET MVC to build a Content Management System parts of a website and have the odious job of recreating all of my Views as Partial Views as it appears to be breaking the way the site map works.

For example, my FAQAdminController has the Views: Index, AddFAQ, EditFAQ, ConfirmDeleteFAQ and these have to become partial views.

I have been told that each Controller should have a single View and all other forms or actions that end in page content to be displayed should be implemented as Partial Views.

I have checked before posting and no documentation, articles, wikis or SO questions give me a straight answer as to whether or not having multiple Views per Controller is breaking the MVC model.

Strictly, should an MVC Controller and View have a 1 to 1 relationship?

+9  A: 

I have been told that each Controller should have a single View and all other forms or actions that end in page content to be displayed should be implemented as Partial Views.

That's nonsense.

Strictly, should an MVC Controller and View have a 1 to 1 relationship?

Absolutely not. Design your application in a logical and consistent way.

A controller usually handles many actions and returns many different views. You could consider having a FAQController to render all the views, for both user and admin.

Developer Art
+5  A: 

I think that defeats the purpose of MVC. As controller should be able to decide which view to use to present model.

TheVillageIdiot
+2  A: 

MVC Controller should be able to support more than one View.

Anwar Chandra
A: 

MVC Controllers can and should support multiple views. It is helpful to have the views supported by a single controller relate to the same business object or process.

Consider the example below

public class ExampleController : Controller
{
    public ActionResult Index()
    {
            //get list of objects
            return View(); // uses a view called Index
    }

    public ActionResult Edit(string id)
    {
            Object target = ObjectManager.GetObject(id);
            if (target == null)
            {
                    return New();//view for creating a record
            }
            else
            {
                    ViewData.Add("detail", target);
                    return View("Detail");//using a view not name-mapped to controller method name
            }
    }

    public ActionResult New()
    {
            return View();  
    }

}
Mike