If someone opens the Edit screen for a row and does nothing but look, how can I get the OnPostAsync to exit instead of updating some fields and saving?
//POST
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
I want to exit here if nothing changed
Dances_Moderated.LastUpdated = DateTime.Today;
Dances_Moderated.DanceStatus = "WaitingOK";
Dances_Moderated.UserID = Convert.ToInt32(HttpContext.Session.GetString("UserID"));
_context.Attach(Dances_Moderated).State = EntityState.Modified;
CodePudding user response:
An easy way is just to check against the database record which you are trying to update. If none of the values have changed, then you can return from your action, before modifying lastUpdated, danceStatus, et. cetera
CodePudding user response:
You can try to use js to check if someone changed the fields.Use a js varaible to store the default value,and before calling OnPostAsync
,comparing the new data and the js variable.And add a route parameter Edited
to pass data to OnPostAsync,if data is edited,Edited
is true.Else,Edited
is false.