C
C#15mo ago
XD

❔ Show error text message under update text box through server validation without refreshing

So basically I want to show an error text message if the user updates and submits an invalid value, but in my code when the user submits a wrong value the page will refresh, the update textbox will be hid again (it's hidden unless the user presses an update button) and the error message will be displayed in two textboxes. Is my only solution implementing client-side validation for my update textbox? My code: Index.cshtml: https://pastebin.com/EhWcWBxC HomeController: https://pastebin.com/rB9q3Uiv TodoModel: https://pastebin.com/SjW0Mben
Pastebin
@model Models.ViewModels.TodoViewModel@{ ViewData["Title"] = "To...
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.
Pastebin
using Microsoft.AspNetCore.Mvc;using Models;using System.Diagnostic...
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.
Pastebin
using System.ComponentModel.DataAnnotations;namespace Models{ pu...
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.
No description
No description
11 Replies
JakenVeina
JakenVeina15mo ago
Is my only solution implementing client-side validation for my update textbox?
yes, in that you have to have client-side code to update the view without a page refresh the only way the page changes without a call to the server is if there's code running client-side that does that you can have that code call to the server, if that's what you want but you need client-side code to have client-side rendering updates
XD
XDOP15mo ago
alright, thank you for your help! regarding server-side validation: do you think removing the validation text for the update textbox and leaving the one that is at the top is ok?
JakenVeina
JakenVeina15mo ago
uhhhh I dunno not quite sure of the UX context
XD
XDOP15mo ago
it's a project of mine but i want to implement the best practices i can
JakenVeina
JakenVeina15mo ago
yeah, but I mean what's the user experience? I don't really know what anything in that screenshot means, business-wise how do I get to that point?
XD
XDOP15mo ago
user can create a to-do after submitting the form at the top. then, if the user clicks on one to-do's update button a textbox will be shown as in the screenshot if the user enters an invalid value the page will refresh, the to-do form at the top will show the error shown in the screenshot and the update textbox is hidden (it will show the error shown in the screenshot if you click on the update button once again)
JakenVeina
JakenVeina15mo ago
yeah, that's definitely counter-intuitive the error should appear where the invalid input was placed and if the input is initially hidden, after the submit, that's also counter-intuitive UX-wise, the page after an attempt to update an individual item should look the same as it did before the attempt, I.E. the textbox and button underneath the item should be there and the error should only appear there
XD
XDOP15mo ago
i can achieve that only through client-side validation right?
JakenVeina
JakenVeina15mo ago
I would not say that
XD
XDOP15mo ago
i'll add client-side validation and leave it like that for now thank you @V.EINA Jaken hey @V.EINA Jaken, I found the way to fix the problem i had to add in my Scripts section the following:
@{
await Html.RenderPartialAsync("_ValidationScriptsPartial");
}
@{
await Html.RenderPartialAsync("_ValidationScriptsPartial");
}
Accord
Accord15mo 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.

Did you find this page helpful?