ASP.NET MVC: updated model data is not recognised in view
See original GitHub issueHi there,
first off, I’m rather new to ASP.NET and its ecosystem, so bear with me if wording is not on spot. I don’t want to exclude layer 8 as the root cause of the following problem either, but neither the docs nor intensive usage of search engines helped at all.
Describe the bug
I’m using APS.NET MVC technology for the following.
So, I have a very simple example to cover. Imagine a form, it has two text fields and a checkbox. In order to back this form, I created a simple view model class having two string properties and a bool property. One of the string properties is required while the other is optional.
In my controller there is an action that will simply return a view, getting passed a fresh instance of that model. The view will render the form using the <form asp-route>…, <input asp-for="..."> tags. So far, so good, everything works until now.
Then I have another controller action that is the target of the form. It will check for model validity using the ModelState.IsValid property. If the model is not valid, I want to reset the optional field and unset the checkbox (setting it to false), then render the form again passing the updated model data. Heads up, problem incoming.
Resetting the model and passing it to the view seems to work just fine. Debugging the view shows that the view has the expected data. But, the input elements will still show the data that was input the step before.
This is what I don’t understand, to me it would be logical that the optional field should be empty and the checkbox unchecked, because the model data says so. But maybe I’m missing something (essential).
To Reproduce
Okay, I thought “I’ve tinkered quite a bit in that project, so I’m gonna try to reproduce it in a fresh project”. Done so and unfortunately I was able to reproduce it.
The model class is called CheckBoxTestModel (I stumbled over checkboxes first, then wondered about text fields); the controller is coded in HomeController, views can be seen in Views/Home/Index.cshtml and Views/Home/PostText.cshtml. Apart from these files, it’s just the project template.
Further technical details
- I’m using ASP.NET Core 5 with JetBrains Rider 2020.2 as IDE
❯ dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.100
Commit: 5044b93829
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100\
Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7
.NET SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.100 [C:\Program Files\dotnet\sdk]
3.1.403 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
Best regards
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)

Top Related StackOverflow Question
Hi,
no worries. This snippet works, but I have to say that it looks rather unsatisfying. I actually want to reset the model’s state in a method of the model itself instead of letting the controller handle this, so using
ModelStatecan only be a workaround.I’m probably not understanding how model binding actually works. Apparently @mkArtakMSFT thinks this is a Docs issue, so I’ll try to read into the code a little bit more and if there’s no cleaner solution to this than what you’ve written, I might come up with a different solution altogether.
Anyways, thanks so far 😃
Best regards
Hi,
thanks for your response. Unfortunately your suggestion didn’t make a difference.
Best regards