2010-06-24 5 views
1

J'utilise des vues fortement typées dans mon MVC et j'ai maintenant réussi à montrer tous les éditeurs pour mon formulaire de registre comme je l'aime. Le problème est que j'ai un radiogroupe contenant 4 radiobotton, Lorsque je sélectionne un radiobutton, je ne cache pas certains des éditeurs qui sont liés aux champs de propriété fortement typés.MVC et show/hinde panneaux?

je pouvais créer une fonction javascript comme celui-ci

if(radiobonnton1.value = cehcked){ 
    //Hide not used fields 
    //Show used fields 
} 
else if(radiobonnton2.value = cehcked){ 
... 
} 
... 

Le problème est que ce sera une fonction BIG et je ne suis pas sûr de savoir comment la validation MVC gérer si un éditeur non valide sont caché? Sera-t-il encore possible de soumettre?

Est-ce vraiment le chemin à parcourir?

BestRegards

Répondre

0

J'ai maintenant ajouté ce methid javascript:

$(document).ready(function() { 
$("#ModelViewAd\\.TypeOfAd :radio").change(function() { 


        if (this.id.match('TypeOfAd_Sell$') != null) { 

         $("#ModelViewAd_BuyNowPrice").removeAttr('disabled'); 
         $("#divBuyNowPrice").fadeIn(500, null); 

         $("#divReservationPrice").fadeOut(500, null); 
         $("#ModelViewAd_ReservationPrice").attr('disabled', 'disabled'); 

         $("#divEndDate").fadeOut(500, null); 
         $("#ModelViewAd_EndDate").attr('disabled', 'disabled'); 

         $("#divStartingPrice").fadeOut(500, null); 
         $("#ModelViewAd_StartingPrice").attr('disabled', 'disabled'); 

        } 
        else if (this.id.match('TypeOfAd_Buy$')) { 

         $("#divReservationPrice").fadeOut(500, null); 
         $("#ModelViewAd_ReservationPrice").attr('disabled', 'disabled'); 

         $("#divEndDate").fadeOut(500, null); 
         $("#ModelViewAd_EndDate").attr('disabled', 'disabled'); 

         $("#divStartingPrice").fadeOut(500, null); 
         $("#ModelViewAd_StartingPrice").attr('disabled', 'disabled'); 

         $("#divBuyNowPrice").fadeOut(500, null); 
         $("#ModelViewAd_BuyNowPrice").attr('disabled', 'disabled'); 

        } 
        else if (this.id.match('TypeOfAd_Let$')) { 

         $("#ModelViewAd_BuyNowPrice").removeAttr('disabled'); 
         $("#divBuyNowPrice").fadeIn(500, null); 

         $("#divReservationPrice").fadeOut(500, null); 
         $("#ModelViewAd_ReservationPrice").attr('disabled', 'disabled'); 

         $("#divEndDate").fadeOut(500, null); 
         $("#ModelViewAd_EndDate").attr('disabled', 'disabled'); 

         $("#divStartingPrice").fadeOut(500, null); 
         $("#ModelViewAd_StartingPrice").attr('disabled', 'disabled'); 

        } 
        else if (this.id.match('TypeOfAd_WishRent$')) { 

         $("#divBuyNowPrice").fadeOut(500, null); 
         $("#ModelViewAd_BuyNowPrice").attr('disabled', 'disabled'); 

         $("#divReservationPrice").fadeOut(500, null); 
         $("#ModelViewAd_ReservationPrice").attr('disabled', 'disabled'); 

         $("#divEndDate").fadeOut(500, null); 
         $("#ModelViewAd_EndDate").attr('disabled', 'disabled'); 

         $("#divStartingPrice").fadeOut(500, null); 
         $("#ModelViewAd_StartingPrice").attr('disabled', 'disabled'); 

        } 
        else if (this.id.match('TypeOfAd_Swap$')) { 

         $("#divBuyNowPrice").fadeOut(500, null); 
         $("#ModelViewAd_BuyNowPrice").attr('disabled', 'disabled'); 

         $("#divReservationPrice").fadeOut(500, null); 
         $("#ModelViewAd_ReservationPrice").attr('disabled', 'disabled'); 

         $("#divEndDate").fadeOut(500, null); 
         $("#ModelViewAd_EndDate").attr('disabled', 'disabled'); 

         $("#divStartingPrice").fadeOut(500, null); 
         $("#ModelViewAd_StartingPrice").attr('disabled', 'disabled'); 

        } 
        else if (this.id.match('TypeOfAd_Auktion$')) { 

         $("#ModelViewAd_BuyNowPrice").removeAttr('disabled'); 
         $("#divBuyNowPrice").fadeIn(500, null); 

         $("#ModelViewAd_ReservationPrice").removeAttr('disabled'); 
         $("#divReservationPrice").fadeIn(500, null); 

         $("#ModelViewAd_EndDate").removeAttr('disabled'); 
         $("#divEndDate").fadeIn(500, null); 

         $("#ModelViewAd_StartingPrice").removeAttr('disabled'); 
         $("#divStartingPrice").fadeIn(500, null); 

        } 


      }) 


     }); 

RadioButton est mis sur la validation correcly échoué du serveur au client, mais le javascript est pas runned jusqu'à ce qu'un RadioButton est modifié manuellement?

+1

Déplacez tout ce qui est actuellement dans votre gestionnaire de changement, '$ (" # ModelViewAd \\. TypeOfAd: radio "). Changez (function() {...})', en une nouvelle fonction. Appelez ensuite cette fonction depuis le gestionnaire de changement AND dans la fonction jQuery ready. – Ryan

Questions connexes