4

I have been using MVC for a while now and am quite happy with it overall compared to the old ASP.NET framework. Combine it with jQuery and EF and life is good.

One thing that really annoys me about it though is all the index views I end up having. It seems every one of my controllers has an index action. So I have many views named "Index" and find it hard to keep track of them in the IDE. It is not uncommon to have multiple tabs open with "Index.cshtml", I have no idea what controller it belongs to without hovering over the tab. It gets confusing quick. The same thing ends up happing with Create, Update, Delete actions that are common to a lot of controllers.

Maybe I should include the controller name in the views, to help keep them straight? Curious what others are doing to avoid this problem.

1
  • 1
    If you Ctrl+Tab between the open documents, you'll see the path in the bottom left of the popup window. Still, not great. Commented May 11, 2011 at 22:34

2 Answers 2

1

I have the same problem and in the true "Convention over configuration" style, I've come up with my own convention to use the Controller + Action name for my views.

I use spark, so this was a case of writing a custom descriptor or with Razor, you write a custom view engine that extends from the default RazorViewEngine and build your conventions in there. This article gives you an idea of how to do it.

That way I can have the Index action in the Account controller called AccountIndex.spark (or .cshtml) and I can still return View() or PartialView() from my action without having to specify the view name.

Sign up to request clarification or add additional context in comments.

Comments

0

Nothing stops you from having a different view name. But since the folder name has the controller name, this would not collide with the rest of the views having the same name.

The issue is - as for the MVC framework - views are preferred to have their action name so you can return the default name not having to specifically specify a name. As such you would not want to have an action HomeIndex on the HomeController, would you?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.