2011-02-23 58 views
3

當我正在進行ajax調用時,控制器正在重定向而不更新我的標記,我的代碼如下所示。ajax actionlink重定向而不是更新標記

這是_layout.cshtml

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

,這是web配置是什麼樣子,我也試圖關閉不顯眼的JavaScript後,沒有運氣。

<code> 
    <appSettings> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
</code> 

我控制器的方法是這樣的

<code> 
    [HttpPost] 
     public ActionResult Create(lesson lesson) 
     { 
      if (ModelState.IsValid) 
      { 
       //Save Album 
       lesson.dateCreated = DateTime.Now; 
       lesson.dateSubmitted = DateTime.Now; 
       lesson.statusID = SUBMITTED; 
       lesson.submittedByUserID = getAppUserID(); 
       lesson.prjLessonID = createLessonPrjID(lesson.projectID); 


       storeDB.lessons.InsertOnSubmit(lesson); 
       storeDB.SubmitChanges(); 
       return RedirectToAction("Index"); 
      } 
      // Invalid – redisplay with errors 

      else 
       return View(lesson); 

     } 
</code> 

任何想法?提前致謝。

<code> 
@if (item.statusID != null) 
       { 
         <td id ="approvedmsg">@item.getLessonStatus(item.statusID.Value)</td> 
       } 
       else 
       { 
         <td> </td> 
       } 

       @if (item.statusID != 3) 
       { 
        <td> 

        @Html.ActionLink("Edit", "Edit", new { id = item.lessonID }) | 
        @Ajax.ActionLink("Delete", "Delete", new { id = item.lessonID }, new AjaxOptions { UpdateTargetId = "approvedmsg"}) 
        </td> 
       } 
</code> 

回答

5

嘗試刪除MicrosoftAjax.jsMicrosoftMvcAjax.js,並只使用

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

好後約在這裏http://yobriefcase.posterous.com/unobtrusive-javascript-in-mvc3

+0

感謝,更新腳本解決的問題。我不得不從腳本文件中拖放它們,因爲引用腳本src時我得到了404。 – marknery 2011-02-23 17:03:27

相關問題