Pass ID to Controller

1

I have the problem that when I click the Register button, the City does not pass the ID. Made. The ID is being passed to the screen, but at the time of passing to the controller not.

<div class="alinhado col-md-4">
    <div class="form-group">
        <div class=" alinhadoLabel">
            @Html.Label("Cidade", htmlAttributes: new { @class = "control-label" })
        </div>
        <div class="alinhadoEditor">
            <select class="form-control" id="City"><option value="0">Selecione</option></select>
        </div>
    </div>
</div>

This is the controller:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "PeopleID,Name,Email,Password,Address,Number,Neighborhood,ZipCode,Photo,Type,Active,Validate,DateBirth,Register,CityID")] People people)
    {
        if (ModelState.IsValid)
        {
            db.Peoples.Add(people);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(people);
    }

and here is the error:

    
asked by anonymous 15.12.2016 / 20:40

1 answer

1

You need to set the name of your select to the same property name for the bind to occur. In this case, CityID instead of City

 <select class="form-control" id="CityID" name="CityID"><option value="0">Selecione</option></select>
    
15.12.2016 / 21:05