Next I'm with the Html.BeginForm () where the same submits the model but when it goes to the same control it finds the ModelState.IsValid false. Follows Template, Control and BeginForm Model:
[Table("TB_Estado")]
public class Estado
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public string sigla { get; set; }
public string estado { get; set; }
}
Control [Post] Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Estado estado)
{
if (ModelState.IsValid)
{
db.Estados.Add(estado);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(estado);
}
View Create
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Estado</h4>
<hr />
<div class="form-group">
@Html.LabelFor(model => model.sigla, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.sigla, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.estado, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.estado, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
See the image that illustrates the problem:
AsrequestedbythepersonneltheinspectionoftheKeysandValuesofModelState,hadalreadyanalyzedanditsaysthatitwasnotpossibletoconverttheString,beingthatthefieldsareallStringandsimple,theIDisautoincrement.I'mstartingnowinASP.NETMVCandapologizeforanyNubisse,lol.
Errormessage="The parameter conversion from type 'System.String' to type 'pedicare.sidigital.com.br.web.Models.Estado' failed because no type to convert between these types. ' >