Save button does not save the inserted data
So I have created a save button in my insert view as per screenshot
The code behind it does not save as I wanted
The view lets me insert any value but the button does not save it onclick.
Once clicked there is nothing happening there, even no error messages.
My code here https://pastebin.com/7LyeZxtt Could anyone kindly point me in the right direction?
Pastebin
/Controller/ [AllowAnonymous] public IActionResult InsertListi...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
9 Replies
Did you debug this already?
Did the request even reach your server?
Did you check whether the stored object is valid?
@Sowehaoiu77
Try changing to:
Network tab just got me this https://pastebin.com/stiTYN5g
This exception seems to point to
`
This method is in the API controller class separately created from HomeController (where this save method lies) : you can find the full code for the API controller https://pastebin.com/f73x8fDN
I tried something like this on Program.cs
`
But the exception is not gone
I suppose this exception prevents my code from what it should be doing
Pastebin
System.Text.Json.JsonException: A possible object cycle was detecte...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
you are returning all records from the table?
ups, I did not want to return all the records from the table .. see, I did not understand what my code is doing.
so with this line return await _context.ListingDBTable.ToListAsync();
it will return all records from the table, correct? And it eventually triggers the exception as it causes the circulation or
Yes, it does - But your issue is with the IEnumerable implementation, causing an endless cycle
What's the reason for the ListingProjects to be enumerable if it only contains one entry?
I just got rid of all the IEnumerable implementation, then the exception is gone.
ChatGPT recommended me to make the ListingProjects enumerable (as I wanted to make a collection of vacation listing names)
But now for the sake of simplicity I will learn more about IEnumerable, this one caused me some unwanted exception
Sounds good 👍
you should not use EF entities as DTOs
that's why you're getting an exception about object cycles
EF entities with navigation properties can have cyclical references which causes problems when serializing to JSON