2010-06-24 2 views
1

MVC에서 강력한 형식화 된보기를 사용하고 있으며 이제는 원하는대로 내 등록 양식의 모든 편집자를 표시 할 수 있습니다.MVC 및 show/hinde panels?

문제는 내가 radiobotton을 4 개 포함하는 radiogroup을 가지고 있습니다. 라디오 버튼을 선택할 때 강력한 입력 된 propertie 필드에 바인딩 된 일부 편집자를 숨기려고합니다.

나는 그것이 유효하지 않은 편집기가있는 경우 MVC 유효성 검사를 처리하는 방법을 잘 모르는 큰 기능과 임 것이라고이이

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

문제와 같은 자바 스크립트 함수입니다 만들 수 있습니다 숨겨진? 제출할 수 있습니까?

정말이 방법이 맞습니까?

BestRegards

답변

0

은 지금이 자바 스크립트 methid을 추가 한 :

유효성 검사를 서버에서 클라이언트로 실패했지만 라디오 버튼을 수동으로 변경 될 때까지 자바 스크립트가 runned하지 않습니다에 라디오 버튼이 correcly 설정
$(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); 

        } 


      }) 


     }); 

?

+1

현재 변경 핸들러에있는 모든 항목을 새 기능으로 이동하십시오. '$ ("# ModelViewAd \\. TypeOfAd : radio"). (function() {{}})', 그런 다음 해당 함수를 변경 핸들러에서 호출하고 jQuery 준비 함수 내에서 호출하십시오. – Ryan