Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

From Microsoft's own built in template for MVC3

The model is extremely skinny, having basically no code.

Model

public class RegisterModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email address")]
    public string Email { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}

While the Controller on the other hand seems to be fat, doing more that simple routing...

Controller

[HttpPost]
[AllowAnonymous]
public ActionResult Register(RegisterModel model)
{
    if (ModelState.IsValid)
    {
        // Attempt to register the user
        MembershipCreateStatus createStatus;
        Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

        if (createStatus == MembershipCreateStatus.Success)
        {
            FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
            return RedirectToAction("Index", "Home");
        }
        else
        {
            ModelState.AddModelError("", ErrorCodeToString(createStatus));
        }
    }

    // If we got this far, something failed, redisplay form
    return View(model);
}
share|improve this question
    
The controller seems skinny enough. As to the model it is a matter of style what you make of them. In this case they are rather data entities which is a perfectly fine approach. –  user8685 Jun 1 '11 at 19:33
2  
Controller is going to hold the instance to the Model and the View but it does not appear as "fat" as you say. –  staticx Jun 1 '11 at 19:58
    
Agreed--perhaps it's a bit more verbose than, say, Rails, but that is largely a byproduct of the language, not the framework. A typical (again, let's say) Rails controller would have very similar code in it. –  Brandon Tilley Jun 2 '11 at 5:01

2 Answers 2

Everything the controller is doing there is its job, its pretty basic stuff. Business logic is not going to be generated for you. Models get fat when you encapsulate useful functionality into them; you can't expect to see that from a template.

share|improve this answer

I'm curious how you think the controller could be put on a diet? I honestly can't see anything there that could move to the model without violating SRP.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.