-2

i am working on mvc4 and would like to add more than a tag on the form. what i had had before was (because i have images to post:

@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))

I would like to add to this form the id. I have looking from this link (How to add ID property to Html.BeginForm() in asp.net mvc?) which has show me that i need to do like this

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "signupform" }))

But due to the fact that my form already have a tag, i don't know how i can add the other tag. The real thing that i would like to do is to change the class of a html element with Jquery basis on the fact that form is valid or not, i have read from these link that i need to use the name of the form to do this (how to check if a form is valid programmatically using jQuery Validation Plugin) and (Catch Client Side Validation failure). By combining these answer, i obtain the following javascript code:

$("#bucton").click(function () {
if (!$('form_id').valid()) {
    $('.firstclass').addClass('secondclass').removeClass('firstclass');
}}); 

where bucton is the name of the input which allows submitting the form and firstclass and secondclass are class to change. any help would be appreciated

Community
  • 1
  • 1
  • 1
    No idea what you're trying to achieve. What do you mean by `tag`? You can add a class or other properties like this: `new { id = "your-id", @class="your-class" }` Is that what you're looking for? – Nico Sep 26 '16 at 16:48
  • thank @TheWaywardRaven, i have try to add an id to this tag with success , but i still not able to do what i want. The form contains a div with class name firstclass and a button which allows to submit the form for validation. I would like that if someone submit the form by using the button and that some data of the are incorrect, that the class firstclass of the div be changed by the class name second class. Althought i have obtained the id of the form, i could no success to do this with jquery – El camerounian Sep 26 '16 at 17:05
  • Post your form code with the jquery code. – Nico Sep 26 '16 at 17:41
  • go to this link to see (http://jsfiddle.net/dipakthoke07/xF8hZ/811/#&togetherjs=v8IIQrNJrS) . I would like to change the class of the fieldset if one or more field are invalid, i woulk like to use jquery – El camerounian Sep 26 '16 at 17:56
  • it is this link instead (https://jsfiddle.net/#&togetherjs=hIw00MowOR) all my excuse to have the one before – El camerounian Sep 26 '16 at 18:03

1 Answers1

0

i have finally solve the problem, i wanted to change the class of the fieldset based on the fact that the form is valid or not, and due to the fact that i have not done a lot of research, marks have been removed from my reputation. I finally obtain this from this post (stackoverflow.com/questions/37642629/jquery-to-check-modelstate-is-valid-or-not), sorry for me. With some modifications, i obtain the beside code

jQuery(document).ready(function () {
$("#lebutton").click(function () {
    var isValid = $('#lajoutation').valid();
    //si le formulaire n'est pas valid, on change les class en cours par d'autres classes
    if (!$('#lajoutation').valid()) {
    //la classe du fieldset
        $('.lbordres').addClass('lbordres2').removeClass('lbordres');

        $('.edisec').addClass('edivion').removeClass('edisec');
    }
});

});