• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Error while validation fields in MVC ASP.NET Core

Resolved: Error while validation fields in MVC ASP.NET Core

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have this form, where user sees his account’s amount and can send money to other user just by providing email. The problem is, when user provides wrong data, function returns page, but I get NullExceptionError.
Actually, I think, that validators work fine, but there is something wrong with return type, or with how this function returns page.
Here is Index.cshtml.cs:
Here is Index.cshtml. This is how it form looks like. When I provide wrong data, it show this NullExceptionError in h5.

Answer:

When you POST you lose the state of your Model. You want to fill your Model when you POST.
What I mean with that, is that you GET the page, it works fine. Then you POST some data, the POST code will run, but now it’s in a new instance of PageModel. This means that Model.account is null.
You can do one of two things:
  1. Fill the data before you do return Page()
  2. Redirect to the GET action instead of returning Page().

Good luck!

If you have better answer, please add a comment about this, thank you!

asp.net asp.net-core asp.net-mvc c# model-view-controller
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: net::ERR_HTTP2_PROTOCOL_ERROR by http get request angular 15.2

02/04/2023

Resolved: How do I stop the command from happening if the requirements for it to work aren’t sert Discord.js

02/04/2023

Resolved: How to scroll bottom of div at launch?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.