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

  • SEARCH
  • Home
  • 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 8920057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:10:12+00:00 2026-06-15T06:10:12+00:00

I have a working MVC 4 edit view that edits a stored database record.

  • 0

I have a working MVC 4 edit view that edits a stored database record. This is the relevant section of the Controller:

    //
    // GET: /Occurrence/Edit/5

public ActionResult Edit(int id = 0)
    {
        Occurrence occurrence = db.Occurrences.Find(id);
        if (occurrence == null)
        {
            return HttpNotFound();
        }

        List<SelectListItem> points = new List<SelectListItem>()
        { 
            new SelectListItem() { Text = "0 - (No Points)", Value = "0"},
            new SelectListItem() { Text = "1 - (5 to 14 minutes)", Value = "1"},
            new SelectListItem() { Text = "2 - (15 minutes to 1 hour)", Value = "2"},
            new SelectListItem() { Text = "3 - (1 to 3 hours)", Value = "3"},
            new SelectListItem() { Text = "5 - (Over 3 hours)", Value = "5"},
        };

        ViewBag.Points = points;

        ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "EmployeeName", occurrence.EmployeeID);
        return View(occurrence);
}

This is the points section of the Model:

[Required(ErrorMessage = "The Points field is required.")]
public int Points { get; set; }

And this is the relevant section of the edit view:

    <div class="editor-field">
        @Html.DropDownList("Points")
        @Html.ValidationMessageFor(model => model.Points)
    </div>

When I try to edit a record the points dropdownlist always populates with “0 – (No Points)” no matter what value is stored in the database. Is there a way to bind this dropdownlist so it will display the stored value in the edit view?

  • 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-06-15T06:10:14+00:00Added an answer on June 15, 2026 at 6:10 am

    You’ll need to use DropDownListFor to hook up the field to your Property. You should be passing down the options on the Model down to the view. You’ll want to write up a view model and pass both the occurences AND the options. Then use DropDownListFor

    public class ViewModel {
    
        public List<SelectListItem> PointOptions { get; set; }
    
        [Required(ErrorMessage = "The Points field is required.")]
        public int Points { get; set; }
    }
    

    Populate those in your controller and pass that down instead of using the ViewBag, then use DropDownListFor:

    @Html.DropDownListFor(m => m.Points, Model.PointOptions)
    

    The *For methods will hook up all the relevant “goo” into your html. It ensures an auto-populated value as well as correct binding on the next post.

    Good luck.

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

Sidebar

Related Questions

I have an MVC application that is using MEF for the controllers, all working
MVC 3 VB.NET razor. I have a view that has 4 dropdown boxes in
I'm working on a strongly-typed edit form for a MVC model that contains a
This is for .net MVC project i'm working on I have the following classes:
I am working on a MVC project that is supposed to have one page
I have my own hand-rolled PHP MVC framework for some projects that I'm working
I have an application, built using MVC, that produces a view which delivers summary
I'm working on an MVC 2 project and I have a model that looks
I have an MVC 3 project that I am working on using Entity Framework
I have a controller that looks like this: public ActionResult Sold() { using (WipDBEntities

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.