if an unobtrusive check is not required, disable it and perform all your server-side checks.
You can check the value of the "Submit" button on the server side and continue based on this:
add name
attribute for both send inputs:
<input type="submit" value="Save" name="btnSubmit" /> <input type="submit" value="Save anyway" class="cancel" name="btnSubmit" />
Update the action to accept string btnSubmit
. You can simply put it in your model if you have one.
[HttpPost] public ActionResult Edit(string emailfield, string btnSubmit) { switch (btnSubmit) { case "Save": if(ModelState.IsValid) {
UPDATE
I understand that checking the client simplifies the work, but if you cannot understand what is wrong with Ajax (I am not familiar with this behavior when class = "cancel" is applied to the input), you can write a script that will check the input for sloppy side on server side:
$('input[type=text]').blur(function(){ $.ajax({ url: '/ControllerName/ValidateInput', data: { inputName: $(this).val() }, success: function(data) {
Now you need to create an action that will perform input validation:
public ActionResult ValidateInput(string inputName) { bool isValid = true; string errorMessage = ""; switch (inputName) { case "password"
This is a bit of a hassle, but, as I said, it can work if you do not figure out a client check.
UPDATE
I don’t know why I didn’t think about it at first ... instead of relying on class="cancel"
, you could do something like this:
Give your "anyway" submit input Id:
<input type="submit" value="Save anyway" class="cancel" name="btnSubmit" id="submitAyway" />
Then enter the script as follows:
$('#submitAyway').click(function(evt) { evt.preventDefault(); $('form').submit(); });
I have not tested this, but theoretically this should send the form without checking it. You probably still need server side validation, as I showed in my first example.