Ihaveaneditcontroller,whichreceivesavaluefromthedatabaseandplaysitforview,andthenIwantwiththatviewtoplaythevaluesonthescreen(basictest)...
However,evenwithmycontrollerleadingtotheeditviewpassingaBranchobject,ittellsmethatbranchisnull.Hereismycontrollerandmyview:
publicActionResultEdita(stringnome_filial){Conexaoconexao=newConexao();Filialfilial=newFilial();stringcomando="SELECT A.FILIAL, B.VALOR_PROPRIEDADE FROM FILIAIS A " +
"LEFT JOIN PROP_FILIAIS B ON A.FILIAL = B.FILIAL AND B.PROPRIEDADE = '00814'" +
"WHERE A.FILIAL = @FILIAL";
var parametros = new Dictionary<string, object>
{
{"FILIAL", nome_filial}
};
var rows = conexao.ExecutaComandoComRetorno(comando, parametros);
foreach (var row in rows)
{
filial.filial = row["FILIAL"];
filial.estoque_max = row["VALOR_PROPRIEDADE"];
}
return View(filial);
}
[HttpPost]
public ActionResult Edita(Filial filial) {
return Content(filial.estoque_max.ToString() + filial.filial.ToString());
}
VIEW:
@model MaxEstoqueFiliais.Models.Filial
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Filial</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.filial, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.filial, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.filial, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.estoque_max, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.estoque_max, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.estoque_max, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Subsidiary Class:
public class Filial
{
[DisplayName("Filial")]
public string filial { get; set; }
[DisplayName("Estoque Máximo")]
public string estoque_max { get; set; }
}
Why is my branch object being null, and am I passing it to the view?