MVC - Index Impression Overflow

I have been using MVC for a while, and I'm quite happy with them overall compared to the old ASP.NET framework. Combine it with jQuery and EF and life will be good.

One thing that really annoys me though is all kinds of indexes that I get. It seems that each of my controllers has an index action. Thus, I have many views with the name "Index" and it is difficult for them to track them in the IDE. Often there are several tabs opened with "Index.cshtml", I have no idea which controller it refers to without hanging over the tab. This is confusing fast. The same thing ends with Create, Update, Delete actions that are common to many controllers.

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

+4
source share
2 answers

I have the same problem, and in true convention configuration style, I came up with my own convention to use the name Controller + Action for my views.

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

That way, I can have an Index action in the Account controller named AccountIndex.spark (or .cshtml), and I can still return View () or PartialView () from my action without specifying the name of the view.

+1
source

Nothing prevents you from having a different view name. But since the folder name has the controller name, it will not interfere with other views that have the same name.

The problem is that, as with the MVC structure, views are preferable to have a name for their action, so that you can return the default name without a special name. So you wouldn’t want to have a HomeIndex action on the HomeController , could you?

0
source

All Articles