1

I currently have a table of series. In this table, a field status_id exists, which is the foreign key linking to a table Status. A status can be new, running, ended,...

My model classes are looking like this:

public partial class Serie
{
    public Serie()
    {
        this.Episodes = new HashSet<Episode>();
    }

    public int ID { get; set; }
    public string Name { get; set; }
    public string Country { get; set; }
    public Nullable<int> Status_id { get; set; }

    public virtual ICollection<Episode> Episodes { get; set; }
    public virtual Status Status { get; set; }
}

Status:

public partial class Status
{
    public Status()
    {
        this.Series = new HashSet<Serie>();
    }

    public int ID { get; set; }
    public string Name { get; set; }

    public virtual ICollection<Serie> Series { get; set; }
}

When editinga serie, I'd like to have a dropdown list of all possible statuses (the name field) and receive this when a user submits the form. What's the best way to accomplish this?

2 Answers 2

1

The simplest answer is that you need to a List of Executives, pass the list in a model back to your View, create a select list, and render a drop down list.

public ActionResult EditSomething()
{
    Model Model = new Model();
    Model.statusList = {some method to fill IEnumerable<status>};

    return View(Model);
}

In your View:

@Html.DropDownListFor(model => model.Id, new SelectList(Model.statusList, "Id", "Name "))
Sign up to request clarification or add additional context in comments.

Comments

0

You need to create the dropdown list using <%= Html.DropDownList("StatusId", Model.Statuses)%>. You would populate your view model with all possible statuses, the record the id of the status the user selected in a variable that gets sent with your view model when the user submits the form. Here is an article detailing the process: http://odetocode.com/blogs/scott/archive/2010/01/18/drop-down-lists-and-asp-net-mvc.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.