3
Next I am with Html.Beginform() where the same Submits the model however when it goes to the control it is false the Modelstate.IsValid. Follows Model, 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 illustrating the problem:
As requested by the staff the inspection of the Keys and Values of Modelstate, had already analyzed and the same says that it was not possible to convert the String, being that the fields are all String and simple, the ID is auto increment. I am starting now at ASP . NET MVC and I apologize for any Nubisse, rsrsrrsrs.
Error message = "The Parameter Conversion from type 'System.String' to type 'pedicare.sidigital.com.br.web.Models.Status' failed because no type converter can Convert between These types."
the object
estado
is coming null... it means it is not valid. It is not wrong.– Ricardo
Inspect the
ModelState
, propertyValues
.– Leonel Sanches da Silva
In the same image you posted, if you click on the arrows of
> Keys
and>Values
, he’ll show you exactly what’s going on.– Randrade
What is the
@model
of his View?– Leonel Sanches da Silva
First sample of code I put, this is my biggest problem, I don’t understand why not recognize as String.
– Napoleão Menezes
Someone can help this case.
– Napoleão Menezes
Difficult this case. Looking for other means.
– Napoleão Menezes