0

My Model:

public class Message
{
    public string text { get; set; }
    public int reloads { get; set; }
}

My Controller:

[HttpPost]
    public IActionResult LoadPage(Message model)
    {
        ++model.reloads;
        return View(model);
    }
    public IActionResult LoadPage()
    {
        return View();
    }

And finally my view:

@if (@Model != null)
{
    <h1>reloads: @Model.reloads</h1>
    <p>@Model.text</p><br />
}
<form asp-action="LoadPage" method="post">
    <input asp-for="text" type="text" />
    <input asp-for="reloads" type="hidden" />
    <input type="submit" />
</form>

I have tried so many different versions of this and it wont increment the reload-int.

Gustav
  • 29
  • 3
  • Because `` uses the value from `ModelState` - refer [this answer](https://stackoverflow.com/questions/26654862/textboxfor-displaying-initial-value-not-the-value-updated-from-code/26664111#26664111) to understand the behavior) –  Feb 10 '18 at 21:59
  • Your creating a new view, therefore the correct approach is to follow the PRG pattern and redirect. –  Feb 10 '18 at 22:10

0 Answers0