0
In the Index Method I can set values in the model and initialize my VIEW with predefined value. But when I do the POST for the START method, when I change the Aquedica property, the value is not being passed to the view, it actually happens with any property that I change the value of the model. NOTE: I tried to use the form below where I found in STACK ENGLISH but nothing solved.
ModelState.SetModelValue("PropertyID", new ValueProviderResult("New value", "", CultureInfo.InvariantCulture));
public class NivelUmController : Controller
{
    private BONivelUm _BONivelUm;
    // GET: NivelUm
    public ActionResult Index()
    {
        NivelUmModel model = new NivelUmModel();
        model.Potencia = 10;
        model.Tempo = 0;
        return View("Index", model);
    }
    [HttpPost]
    public ActionResult Iniciar(NivelUmModel model)
    {
        if (ModelState.IsValid)
        {
            _BONivelUm = new BONivelUm();
            _BONivelUm.Microondas.Potencia = 7;
            _BONivelUm.Microondas.Tempo = 20;
            model.Aquecida = _BONivelUm.Iniciar();
        }
        return View("Index", model);
    }
    [HttpPost]
    public ActionResult IniciarRapido(NivelUmModel model)
    {
        if (ModelState.IsValid)
        {
            _BONivelUm = new BONivelUm();
            model.Aquecida = _BONivelUm.IniciarRapido();
        }
        return View("Index", model);
    }
}
VIEW:
@model App.MicroondasDigital.Web.Models.NivelUm.NivelUmModel
@{
    ViewBag.Title = "Microondas Nível 1";
}
<div class="container">
    <div class="row">
        <h2>Parametrização</h2>
        @using (Html.BeginForm("Index", "NivelUm", FormMethod.Post))
        {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)
            <div class="form-group">
                @Html.LabelFor(m => m.Tempo, new { @class = "form-label" })
                @Html.TextBoxFor(m => m.Tempo, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.Tempo)
            </div>
            <div class="form-group">
                @Html.LabelFor(m => m.Potencia, new { @class = "form-label" })
                @Html.TextBoxFor(m => m.Potencia, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.Potencia)
            </div>
            <input class="btn btn-block" id="btnIniciar" type="button" value="Iniciar" />
            <input class="btn btn-block" id="btnIniciarRapido" type="button" value="Iniciar Rápido" />
            <br />
            <div class="form-group">
                @Html.TextAreaFor(x => x.Aquecida, 10, 10, new { @class = "form-control" })
            </div>
        }
    </div>
</div>
@section Scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnIniciar').click(function () {
                $.post("NivelUm/Iniciar", $("form").serialize(), function (data) {
                });
            });
            $('#btnIniciarRapido').click(function () {
                $.post("NivelUm/IniciarRapido", $("form").serialize(), function (data) {
                });
            });
        })
    </script>
}
You’re starting the View again, where you preload the data, the idea is you return only the model!
– Marconi
@Marconi, I don’t understand your comment! Could detail better?
– Nicola Bogar
Puts a break point on
Index()!– Marconi
Putzzzz, I got it.. As I’m calling View("Index", model), it will go through my Action Index again, that’s right?
– Nicola Bogar
That’s right Nicola rs, I just know curious Asp.net MVC, if I’m not mistaken you have to return a Jsonresult
– Marconi
Or I can create another View for my Start Action, and another one for Homerapido! Comprreendi! Thanks.. rs
– Nicola Bogar
@Nicolabogar, did you solve it? took a look at my answer?
– Leandro Angelo
@Leandroangelo, I tried to do the way you said but I could not, I solved my problem returned a Json result and populating my components with Jquery
– Nicola Bogar