0
Good afternoon Guys, I’m having trouble with my application, when I will edit a record that on the screen has a Dropdownlist it appears --Selecione--
, where should appear what was saved in the bank. How to do this?
I am using Visual Studio 2015 - ASP.Net Mvc 4 and Entityframework as a bank.
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 na 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’s wrong? Thank you very much.
Welcome to SOF! We need some more information like: language used, framework, etc. Could edit the question?
– Leonardo Pessoa
Thank you Leonardo. I edited my question. I hope someone will help me.. kkkkkkkk.
– Paulinho
And the editing method? EF is not bank, it is ORM.
– Aline