Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 376711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:37:33+00:00 2026-05-12T14:37:33+00:00

After watching this video , I am wondering if I am using my controllers

  • 0

After watching this video, I am wondering if I am using my controllers wrong. What exactly should a controller contain?

For my blog, I have a post controller which has methods:
create
show
list
loadPost
like
dislike

Whereas my post model only has a few access rules, validation rules and relation information. Are there any examples of a MVC app on the web?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:37:33+00:00Added an answer on May 12, 2026 at 2:37 pm

    I highly recommend reading
    http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/04/24/how-we-do-mvc.aspx

    Here’s my incomplete list of what controller shouldn’t do:

    • bind post data to view model – no, model binders should do this
    • get entities from repositories – I’d say no, model binders or action filters should
    • calculate something – no, view models or entities should
    • authorization – maybe, but it’s better pass to attributes/filters
    • validation – only if it come back from entities/domain (i.e. business rules), view models (presentation) validation should be handled automatically (binders, etc)

    Should do:

    • get bound, validated view model as input
    • call domain layer, passing data from view model
    • handle domain layer errors
    • route to appropriate action/view depending on view model / domain results

    Bad:

    public ActionResult PlaceOrder(Guid orderid)
    {
      if (HttpContext.Session["user"] == null)
        return Redirect("Login");
      if (!ValidOrderId(orderid)) return Redirect();
      var order = cart.Get(orderid);
      if (order == null) { ViewData["orderid"] = orderid; return View("Select"); }
      order.Status = OrderStatus.Placed;
      foreach (var item in order.Items)
        item.Update();
      var cart = Cart.GetCurrent();
      cart.Save(order);
      return Redirect("Show", "Orders", new { orderid = orderid });
    }
    

    Good

    [Authorize]
    [ModelStateToTempData]
    // OrderViewModel.Id/OrderViewModel.Instance - validates id, 
    // gets it from repository, set Instance or ModelState error
    public ActionResult PlaceOrder(OrderViewModel<Order> order)
    {
      if (!ModelState.IsValid)
         return View("Select", order);
      var order = order.InstanceFromDatabase;
      _injectedCart.SetOrderPlaced(order);
      return RedirectToAction<OrdersController>(c => c.Show(order));
    }
    

    And by the way, I rarely see good MVC examples, including the NerdDinner. They all deal with business logic inside actions, no view models, and so on. This is usually OK for what they are intendet for – MVC features demonstration – but it shouldn’t be taken as good design examples. A more-or-less good examples is CodeCampServer, along with accompanion book ASP.NET MVC In Action. But not without its drawbacks (anemic domain model, for example).

    But if do not try to follow domain driven design, and instead have a simple data-driven requirements, things can be easier for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Introduction After watching this video from LIDNUG, about .NET code protection http://secureteam.net/lidnug_recording/Untitled.swf (especially from
I have developed a few applications now all using single view controllers. In each
After watching The Dark Knight I became rather enthralled with the concept of the
After watching: The Clean Code Talks -- Inheritance, Polymorphism, & Testing I checked my
After reading the Head First Design Patterns book and using a number of other
After reading this question , I was reminded of when I was taught Java
After lots of attempts and search I have never found a satisfactory way to
I just finished watching the Google clean code video on YouTube (see link ,
I will start by saying this is the first time I have done anything
After reading ASP.NET MVC 2 in Action and watching Jimmy Bogard's presentation from MvcConf

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.