Click here to Skip to main content
15,904,155 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Progress with MVC Pin
Marc Clifton13-Apr-15 4:31
mvaMarc Clifton13-Apr-15 4:31 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 4:42
User 1013254613-Apr-15 4:42 
GeneralRe: Progress with MVC Pin
Bergholt Stuttley Johnson13-Apr-15 4:56
professionalBergholt Stuttley Johnson13-Apr-15 4:56 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 5:05
User 1013254613-Apr-15 5:05 
GeneralRe: Progress with MVC Pin
Bergholt Stuttley Johnson13-Apr-15 5:36
professionalBergholt Stuttley Johnson13-Apr-15 5:36 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 5:46
User 1013254613-Apr-15 5:46 
GeneralRe: Progress with MVC Pin
Bergholt Stuttley Johnson14-Apr-15 21:28
professionalBergholt Stuttley Johnson14-Apr-15 21:28 
GeneralRe: Progress with MVC Pin
User 1013254614-Apr-15 22:30
User 1013254614-Apr-15 22:30 
Bergholt Stuttley Johnson wrote:
I can see what you are getting at I think, firstly still not sure why you need a new controller for each view? if its only initialization then you can put them all in one controller, unless you are calling the views the same name!

Not quite, as it's also relevant to actions within controllers. An example:
  • Views
    • Home
      • Index.cshtml (pretty much static content)
      • UsagePolicy.cshtml (pretty much static content)
    • Customers
      • Index.cshtml (pretty much static content)
      • List.cshtml (a list of customers)
      • Edit.cshtml (the "edit customer" form)
    • Shared
      • _Layout.cshtml
With ASP.NET MVC as it currently stands, I need the following controllers and actions:
C#
public class HomeController : Controller
{
  public ActionResult Index()
  {
    return View();
  }

  public ActionResult UsagePolicy()
  {
    return View();
  }
}
C#
public class CustomerController : Controller
{
  public ActionResult Index()
  {
    return View();
  }

  public ActionResult List()
  {
    ..Customer list logic
  }

  [HttpGet]
  public ActionResult Edit()
  {
    ..Form initialization logic
  }

  [HttpPost]
  public ActionResult Edit()
  {
    ..Form relevant logic
  }
}
What I'm suggesting reduces the code down to this (HomeController is no longer needed):
C#
public class CustomerController : Controller
{
  public ActionResult List()
  {
    ..Customer list logic
  }

  [HttpGet]
  public ActionResult Edit()
  {
    ..Form initialization logic
  }

  [HttpPost]
  public ActionResult Edit()
  {
    ..Form relevant logic
  }
}
Surely reducing the amount of code down in any project makes sense more than writing the same code in different classes over and over again?
Bergholt Stuttley Johnson wrote:
hink of it as similar to initialising a variable, you do that hundreds of times too but accept that as part of the process.

Not quite (again). I only add a variable where I have a use for it - it's optional. Actions (and controllers) are mandatory whether or not I have any logical code to add.

Common methods would normally be placed within a base class, or you might decide to add in a route, but that still means recompiling and re-publishing the entire application every time someone adds a new view/action name.

What I'm getting at is this: why not (in ASP.NET MVC) make actions (and controllers) optional, in that I only write them if I actually need to include some functional code? The default behaviour should be (in my opinion) that if a route is requested that goes through to a view without an action and/or controller, then it simply returns the view.
Bergholt Stuttley Johnson wrote:
f you object to that then don't use MVC

I love ASp.NET MVC, but even the MVC guys themselves work on improving it. If we just accept things as they are, we'll never move forward Smile | :)
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.


modified 31-Aug-21 21:01pm.

GeneralRe: Progress with MVC Pin
Bergholt Stuttley Johnson14-Apr-15 22:47
professionalBergholt Stuttley Johnson14-Apr-15 22:47 
GeneralRe: Progress with MVC Pin
User 1013254614-Apr-15 23:05
User 1013254614-Apr-15 23:05 
GeneralRe: Progress with MVC Pin
Kevin Marois13-Apr-15 4:52
professionalKevin Marois13-Apr-15 4:52 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 4:58
User 1013254613-Apr-15 4:58 
GeneralRe: Progress with MVC Pin
Vark11113-Apr-15 7:57
Vark11113-Apr-15 7:57 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 8:04
User 1013254613-Apr-15 8:04 
GeneralRe: Progress with MVC Pin
Vark11113-Apr-15 8:06
Vark11113-Apr-15 8:06 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 8:14
User 1013254613-Apr-15 8:14 
GeneralRe: Progress with MVC Pin
Vark11113-Apr-15 8:23
Vark11113-Apr-15 8:23 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 8:30
User 1013254613-Apr-15 8:30 
GeneralRe: Progress with MVC Pin
Bergholt Stuttley Johnson13-Apr-15 5:02
professionalBergholt Stuttley Johnson13-Apr-15 5:02 
GeneralRe: Progress with MVC Pin
Bergholt Stuttley Johnson13-Apr-15 4:16
professionalBergholt Stuttley Johnson13-Apr-15 4:16 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 4:22
User 1013254613-Apr-15 4:22 
GeneralRe: Progress with MVC Pin
Bergholt Stuttley Johnson13-Apr-15 4:27
professionalBergholt Stuttley Johnson13-Apr-15 4:27 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 4:30
User 1013254613-Apr-15 4:30 
GeneralRe: Progress with MVC Pin
Bergholt Stuttley Johnson13-Apr-15 4:40
professionalBergholt Stuttley Johnson13-Apr-15 4:40 
GeneralRe: Progress with MVC Pin
User 1013254613-Apr-15 4:49
User 1013254613-Apr-15 4:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.