2012-07-22 82 views
0

我尝试提交表单通过按下一个按钮,最终将刷新表MVC 3 Ajax.BeginForm提交问题

这是形式:

@{ 
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> 
} 

这是的Controler:

公众的ViewResult刷新(){

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

由于某种原因,当我提交按钮没有发生

我已经添加

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

感谢 三木

+0

检查与断点在'Refresh'方法你的行动正在被调用。你能在浏览器开发控制台看到请求吗? (在Chrome中,IE可以通过F12访问它,在FF中查找网络标签,你可以使用萤火虫) – nemesv 2012-07-22 10:59:38

+0

断点没有捕捉到任何东西或网络标签:( – MIkCode 2012-07-22 11:09:51

回答

1

不显眼JS助手上的提交事件侦听与

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

但是你的“提交”按钮是“只需一个按钮,”没有一个提交按钮:

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

将其更改为type="submit",它应该工作:

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

更改为type =“submit”,它应该工作: 修复它谢谢:) :) :) – MIkCode 2012-07-22 11:37:33