Changes in ASP.NET mvc client applications

In my application, I want the client not to click submit when it does not change the values ​​in a specific form. I can do this serveride and add viewmodelerror to modelstate. But is there a way to do this also clientide with javascript? I was looking for him, but could not find him.

+7
source share
3 answers

You can set the javascript variable if the form is edited. An easy way to do this would be to listen for a change event in the input fields:

var isChanged = false; $('input,select,textarea').change(function() { isChanged = true; }); 

And then check isChanged before submitting.

This approach does not take into account the values ​​returned back to the original value.

If you need to solve this scenario, you need to save the state of the form in a javascript object and compare it with this.

You can add this to prevent the user from leaving the page if the form has changed:

 $(window).bind('beforeunload', function() { if (isChanged) { return 'You have changed the form, are you sure?'; } else { return undefined; } }); 
+16
source

Not sure what you are asking? Are you talking about client side validation? in this case you can use MVC Validation or javascript library like jquery and use validation plugin

0
source

What should the client change?

If, for example. it's just the value of the text field, you can save the original value in the jquery event ready for the document, and when you click the submit button, run the javascript function, which checks if the value has changed.

If you have more complex input fields, you can still use this mechanism to save the original and check for javascript submission.

0
source

All Articles