Div不会使用Ajax.ActionLink刷新

时间:2011-06-30 16:22:11

标签: ajax asp.net-mvc-3

我正在尝试使用Ajax.ActionLink刷新页面上的项目列表。我可以在没有问题的情况下在测试页面中获得基本的Ajax更新,但在这种特殊情况下,我无法让它工作。

我的索引控制器和视图非常简单(见下文)。索引视图呈现列表操作,这是列出我的项目和我的AjaxLinks的位置。 AjaxLinks调用“UpdateStatus”操作,该操作会更改项目的状态。在那之后,List不再显示该项,因此我返回List操作。

但是,虽然代码全部正确执行且没有错误,但页面不会更新或刷新。

有人能看到我的问题吗?

    Public Function Index(Optional ByVal status As String = "Pending") As ActionResult

        ViewBag.Status = status
        Return View()

    End Function

    Public Function List(Optional ByVal status As String = "Pending") As ActionResult

       'Code to populate the model with the filtered list is here'

        Return View(plvm)
    End Function

    Public Function UpdateStatus(ByVal id As Integer, ByVal status As String, ByVal actionStatus As String)
        'Code to update the status is here'

        db.SaveChanges()

        Return List(status)
    End Function

Index.vbhtml:

    @Code
        ViewData("Title") = "Proposals"
        Layout = "~/Views/Shared/_Layout.vbhtml"
    End Code

    @* Some additional render code is here *@

    <div id="dashboardDetails">   
        @Code        
            Html.RenderAction("List", "Proposals", New With {.status = ViewBag.Status})
        End Code
    </div>

List.vbhtml:

@ModelType CharityMVC.ProposalListViewModel

@Code    
    Layout = ""
End Code
@* Some addtional render code is here (table tags, etc...)  *@
<tbody>
        @For Each item As CharityMVC.Program In Model.Programs
            @:<tr id="prop @item.Id">
                @:<td>@item.Proposal.Organization.Name</td>
                @:<td>@item.Name</td>
                @:<td><div class="buttons">     
                        @Ajax.ActionLink("ajax link", "UpdateStatus", New With {.id = item.Id, .actionStatus = "Tabled", .status = ViewContext.RouteData.Values("status")}, New AjaxOptions With {.UpdateTargetId = "dashboardDetails"})                                        
                @:</div></td>
            @:</tr>

        Next
    </tbody>

</table>

1 个答案:

答案 0 :(得分:0)

到目前为止我最好的猜测/答案:

它似乎与我“嵌套”返回的方式有关(返回列表函数)。

如果我在UpdateStatus中复制List()方法调用并使用以下行:

Return View("List",plvm)

它有效。

有时它不返回任何数据,只是将整个列表空白并将其保留在那里,我必须重新加载整个页面。这是ajax实现中的错误吗?