2012-07-22 4 views
0
question

im essayant de soumettre un formulaire en appuyant sur un bouton qui éventuellement actualiser la tableMVC 3 Ajax.BeginForm soumettre

c'est la forme:

@{ 
AjaxOptions ajaxOpts = new AjaxOptions 
{ 
    Confirm = "start ???", 
    UpdateTargetId = "MainTable", 
    InsertionMode = InsertionMode.Replace, 
    Url = Url.Action("Refresh","MainScreen"), 
    LoadingElementId = "loading", 
    LoadingElementDuration = 2000, 



};} 
@using (Ajax.BeginForm(ajaxOpts)){ 

<div id="loading" style="display: none; color: Red; font-weight: bold"> 
    <p> 
     Loading Data...</p> 
</div> 

<div id="header"> 

    <input type="button" value="Submit Form" /> 

</div> 
<table id="MainTable"> 
    <tr> 
     <th> 
      ServiceId 
     </th> 
     <th> 
      ServiceInstanceId 
     </th> 
     <th> 
      MessageRole 
     </th> 
     <th> 
      Datetime 
     </th> 
     <th> 
      Message 
     </th> 
     <th> 
      Status 
     </th> 
     <th> 
      ESBErrorCode 
     </th> 
     <th> 
      ESBTecnicalErrorCode 
     </th> 
     <th> 
      ErrorDescription 
     </th> 
     <th> 
      PortName 
     </th> 
     <th> 
      MachineName 
     </th> 
     <th> 
      ConsumerId 
     </th> 
     <th> 
      ExternalId 
     </th> 
     <th> 
      ConsumerMachineName 
     </th> 
     <th> 
      ServiceBehavior 
     </th> 
     <th> 
      RouterConsumerId 
     </th> 
     <th> 
     </th> 
    </tr> 
    @foreach (var item in Model) 
    { 
     <tr> 
      <td> 
       @Html.DisplayFor(modelItem => item.ServiceId) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.ServiceInstanceId) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.MessageRole) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.Datetime) 
      </td> 
      <td> 
       \ 
       @Html.DisplayFor(modelItem => item.Message.Context) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.Status) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.ESBErrorCode) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.ESBTecnicalErrorCode) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.ErrorDescription) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.PortName) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.MachineName) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.ConsumerId) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.ExternalId) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.ConsumerMachineName) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.ServiceBehavior) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.RouterConsumerId) 
      </td> 
     </tr> 
    } 
</table> 
} 

c'est le Controler:

ViewResult Refresh (public) {

 var tracks = db.Tracks.Include(t => t.Message); 
     return View(tracks.ToList()); 
    } 

pour une raison quelconque lorsque je soumets le bouton rien ne se produit

i déjà ajouté

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> 

grâce miki

+0

Vérifiez avec un point d'arrêt dans votre méthode 'Refresh' que votre action est appelée. Pouvez-vous voir la demande dans la console de développement de votre navigateur? (dans Chrome, IE vous pouvez y accéder avec F12 chercher l'onglet réseau dans FF vous pouvez utiliser firebug) – nemesv

+0

le point de rupture n'a rien attrapé ou l'onglet réseau :( – MIkCode

Répondre

1

aide de la discrète écoute sur l'événement soumettre avec

$("form[data-ajax=true]").live("submit"... 

mais votre bouton « Envoyer » est « juste un bouton » pas un bouton de soumission:

<input type="button" value="Submit Form" /> 

changement à type="submit" et il devrait fonctionner:

<input type="submit" value="Submit Form" /> 
+0

Changez-le en type = "soumettre" et il devrait travail: cela corrige merci :) :) :) – MIkCode

Questions connexes