2012-04-05 11 views
7

Używam Ajax.Begin formularz w mojej aplikacji MVC 3 + RazorAjax.BeginForm z OnBegin uniemożliwić działanie na miano

using (Ajax.BeginForm("ActionName", "ControllerName", new AjaxOptions { OnBegin = "ValidateDateFunction('" + @abc.xyz + "')", HttpMethod = "POST", UpdateTargetId = "savebutton" })) 
    { 
     <input type="submit" value="Save" /> 
    } 

Poniżej jest jak moja metoda onBegin wygląda. Przekazuję wartość tej metodzie, jestem w stanie uzyskać prawidłowy alarm.

function ValidateDateFunction(id) { 
     alert(id); 
     if(some-ConditionUsing-formId) 
     { 
      return false; 
     } 

     return true;   
    } 

Teraz, gdy używam tego, chciałem, aby mój stan się nie powiódł, wtedy nie należy wywoływać akcji. Ale tutaj, w moim przypadku, w obu warunkach moje działanie jest wywoływane.

Proszę o pomoc w tej sprawie.

Poniżej jest mój rzeczywisty sposób validate

 function ValidateDateFunction(fId) { 

     var first = document.getElementById("startDate" + fId); 
     var second = document.getElementById("endDate" + fId); 

     if (first.value == "" && second.value != "") { 
      alert("Please select both dates"); 
      return false; 
     } 
     else if (first.value != "" && second.value == "") { 
      alert("Please select both dates"); 
      return false; 
     } 

     var startDateVal = new Date(first.value); 
     var endDateVal = new Date(second.value); 

     if (startDateVal.getTime() > endDateVal.getTime()) { 
      alert("Error ! The start date is after the end date!"); 
      return false; 
     } 
     alert('should not reach here'); 
     return true; 

    } 
+0

znalazłeś! prostu musiałem podkręcić mój OnBegin właściwość OnBegin = "return ValidateDateFunction ('" + @ abc.xyz + "')" link odniosłem http://stackoverflow.com/questions/8056968/asp -net-mvc-3-0-ajax-actionlink-onbeign-function-true-the-execute-action-action – Yasser

+0

co chcesz przekazać? – HaBo

+0

znalazłem http://stackoverflow.com/questions/10024135/ajax-beginform-with-onbegin-prevent-action-to-be-called/10039566#10039566 – Yasser

Odpowiedz

Powiązane problemy