Does ajax post supports the usual validation upon submit of a form?
Is
@using(Html.BeginForm()){
@Hml.ValidationSummary()
<input type="submit" value ="Save">
}
same as
@using(Html.BeginForm(new {id=FormTest})){
@Hml.ValidationSummary()
<input type="button" value= Save>
}
<script type="javascript">
$("#Save").click(function(){
$("#FormTest").submit();
});
</script>
There are so many wrong things going on here that I really don’t know where to start.
Your
Html.BeginFormdefinition is wrong: you are confusingrouteValueswithhtmlAttributes. See below for solutionYour button doesn’t have an id so your javascript selector will most probably fail
All those efforts are not necessary because a simple
<input type="submit">button does it out of the box.Now lets suppose that somehow you are a fan of javascript and you want to write it (I don’t know why would you want to write code but anyway). So start by fixing your form definition:
and then you could do this:
obviously you must ensure that the client scripts are properly included on your page:
and of course the real solution I would recommend you is to use a submit button for submitting forms:
Now you don’t need any javascript (obviously you still need the two script inclusions for the unobtrusive validation).