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 6089133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:03:56+00:00 2026-05-23T12:03:56+00:00

This MVC tutorial suggests to make dropdownlists like so: // // POST: /StoreManager/Create [HttpPost]

  • 0

This MVC tutorial suggests to make dropdownlists like so:

//
// POST: /StoreManager/Create
[HttpPost]
 public ActionResult Create(Album album)
 {
    if (ModelState.IsValid)
    {
        db.Albums.Add(album);
        db.SaveChanges();
        return RedirectToAction("Index");  
    }
    ViewBag.GenreId = new SelectList(db.Genres, "GenreId",
"Name", album.GenreId);
    ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId",
"Name", album.ArtistId);
    return View(album);
 }

I’m new to MVC, but it seems to me this isn’t a good separation of concerns because it makes database calls within the controller. Is this correct?

Is there a better way?

  • 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-23T12:03:56+00:00Added an answer on May 23, 2026 at 12:03 pm

    This is up to you to decide on the complexity of your project. The larger the project gets – the least likely you should be to take this approach. I would recommend at the very minimum using the Repository pattern to return your data. Secondly as per the example above it uses ViewBag – this is also something not highly recommended. Sure its ‘cool’ its there – but generally this data you want in a strongly typed View Model that represents the data going to the View, not the dynamic magic of ViewBag that relies on you not mistyping a field name to use correctly.

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

Sidebar

Related Questions

I've been experimenting with ASP.NET MVC and following this tutorial to create the basic
I'm trying to use this tutorial to create a spring mvc user login page.
Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,
in this MVC tutorial it showed how to decouple Controller from database logic using
I'm following this MVC tutorial and when I add a View for the Edit
I am stuck on this Spring MVC tutorial for newbies: http://sites.google.com/site/springmvcnetbeans/step-by-step/ I am the
I am following the spring MVC tutorial and also reading this article on mvc
I'm following this ASP.NET MVC tutorial from Microsoft : My code is slightly different,
I'm follow this tutorial to use CAPTCHA in MVC application: http://coderjournal.com/2008/03/actionfilterattribute-aspnet-mvc-captcha/ I think this
I am working through the Mvc Music Store tutorial and am stuck on this

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.