DropdownList on the Edit screen

0

Good afternoon, I'm having problems with my application, when I'm going to edit a record on the screen that has a DropdownList it appears --Selecione-- , where it should appear what was saved in the database. How to do this? I'm using Visual Studio 2015 - ASP.Net Mvc 4 and the EntityFramework itself as a database.

My Model

[Table("Obras")]
public class Obra
{
    [Key]
    public int ObraId { get; set; }

    [Display(Name = "Tipo da Obra*")]
    public string TipoObra { get; set; }

    [Display(Name = "Descrição da Obra*")]
    public string DescricaoObra { get; set; }

    [Display(Name = "Status*")]
    public string StatusObra { get; set; }

    [Display(Name = "Valor Aproximado*")]
    public string ValorObra { get; set; }

    [Display(Name = "Data de Início*")]
    [DataType(DataType.DateTime)]
    public DateTime DataInicioObra { get; set; }

    [Display(Name = "Previsão de Termíno*")]
    [DataType(DataType.DateTime)]
    public DateTime DataTerminoObra { get; set; }

}

This is the Dropdown part of my View ..

<div class="form-group">
   @Html.LabelFor(model => model.TipoObra,htmlAttributes: new { @class ="control-label col-md-2" })
  @Html.Label("LblObra", "Tipo Da Obra*", new { @class = "control-label col-md-2" })
    <div class="col-md-10">
      @Html.DropDownList("DropTipoObra", new List<SelectListItem>{
        new SelectListItem{ Text = "Construção", Value = "1"},
        new SelectListItem{ Text = "Reforma", Value = "2"},
        new SelectListItem{ Text = "Reparo", Value = "3"},
        new SelectListItem{ Text = "Outros", Value = "4"},
}, "--Selecione--", new { @class = "form-control"})
    </div>
</div>

This is my Create in Controller

// POST: Obra/Create
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "ObraId,TipoObra,DescricaoObra,StatusObra,ValorObra,DataInicioObra,DataTerminoObra")] Obra obra, string DropStatus, string DropTipoObra)
    {
        string recebeTipoObra = DropTipoObra;
        string recebeStatus = DropStatus;

        if (recebeTipoObra == "1")
        {
            obra.TipoObra = "Contrução";
        }
        else
        {
            if (recebeTipoObra == "2")
            {
                obra.TipoObra = "Reforma";
            }
            else
            {
                if (recebeTipoObra == "3")
                {
                    obra.TipoObra = "Reparo";
                }
                else
                {
                    obra.TipoObra = "Outros";
                }
            }
        }

How to do Edit? And what is wrong? Thank you in advance.

    
asked by anonymous 13.03.2017 / 21:33

0 answers