C
C#12mo ago
Fatih

✅ Model not binding to View' issue in ASP.NET

I encountered an issue in my ASP.NET MVC application where the data from the Model is not being properly bound and displayed in the View. The View is not rendering the data I expect, and instead, it appears to be null or empty. I have checked the Model class and Controller code, and they seem to be correct. I need to investigate the root cause of this problem and find a solution to ensure the Model data is properly passed to the View and displayed as expected.
6 Replies
Hackmagician
Hackmagician12mo ago
Is your model state valid for when you pass it to the view?
SinFluxx
SinFluxx12mo ago
shouldn't the data be entered by the user to submit for registration?
Angius
Angius12mo ago
Is the model actually empty when it gets to the backend? Because when it comes to display, I don't think asp-for will show the data from the model asp-for="Stuff" will only generate id="Stuff" name="Stuff" attributes, basically If you want to display the data, you'll need value="@Model.Stuff"
Fatih
Fatih12mo ago
thanks for your answers @ZZZZZZZZZZZZZZZZZZZZZZZZZ @sinfluxx @ℍ I tried the same codes with different newly created controllers and models, it works fine, but I want to use it in the current area. my main problem is model class not binding to view and I cannot transfer the data I entered in the inputs.
hippiewho
hippiewho12mo ago
Maybe add [FromBody] to the parameter list? Like:
Register([FromBody] RegisterModel model)
Register([FromBody] RegisterModel model)
It shouldnt be necessary though and I can't find anything wrong with your code 🤔
Accord
Accord12mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.