I am doing some server stuff that could potentially fail (not likely) but something can go wrong. I want to stop the user from going any further so I want to disable the input so that they have to refresh the page. How can I disable it based on ModelState errors. If any errors exist, disable this box and I only want to do it when the page is initially loaded. My problem is not necessarily how to do it but more what is the standard and the best way to do it. I could have a ViewBag that holds a true false for disabling it but not sure if that’s the best route, any suggestions?
I am doing some server stuff that could potentially fail (not likely) but something
Share
Let’s suppose that you have a POST controller action that does some processing and adds errors to the ModelState if it fails which pretty standard. Now inside the view you could:
or write a custom helper that will do the job and simplify things up for you:
Could be useful if you need this behavior for multiple input fields.