Convention over configuration in ASP.NET MVC
Asked Answered
A

1

12

I am relatively new to ASP.NET MVC, and am very impressed with the clarity of the platform so far. However, there is one aspect that I find uncomfortable.

At first, I accepted the fact that when I say

return View();

I am calling a helper method that returns an ActionResult, and makes some assumptions about which view to present, route values, etc. But lately I have been writing code that looks more like this:

return View("Index", new { id = myID })

because it is immediately clear to me what's happening by reading that single line of code.

Lately I have been struggling with the fact that I can have an Index.ASPX view open on the tabs, and I can't immediately tell where it comes from because the IDE doesn't highlight the current tab in the Object Explorer. I haven't resorted to changing the names of the files to ControllerNameIndex.ASPX, but I do put a title in the view that is more specific. Still, it doesn't help much.

How do you deal with these kinds of ambiguities?

Anticlinorium answered 2/7, 2009 at 4:24 Comment(5)
I've been wondering the same thing - I look forward to reading responses from those more experienced.Sequestered
I've just been relying on knowing which aspect of the site i've been working on and keeping track. Now and again i close all tabs in VS and start again. Now that i think of it that seems a little counter-productive.Fowling
That's what I've been doing. Great minds think alike, I guess. :)Anticlinorium
Do whatever 'fits your mind' best. Having said that, your need for explicit-ness inclines me to believe you're a java/asp.net guy. You have to remember the convention>config argument stems from the ruby camp, where the language and community as a whole leans more that way. So to a c# mindset, you're probably finding it all a bit strange.Bounds
Chris, you should've posted that as an answer.Mindymine
M
6

I think you answered your own question.

There's no hard rule preventing you from calling your views very specific names, such as "ListOfFooBars" or "EditFizzBuzz" or "AddNewGeeblup". The naming convention for the default view engine only specifies that there's a folder corresponding to your model name under views, and there's an ASPX or ASPC file under that folder that corresponds to your view name.

Mindymine answered 2/7, 2009 at 6:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.