开发者

Div won't refresh with Ajax.ActionLink

I am trying to use Ajax.ActionLink to refresh a list of items on my page. I can get basic Ajax updates working in a test page without an issue, but in this particular case I'm not able to get it to work.

My Index Controller and View are fairly simple (see below). The Index View renders the List action, which is where my items are listed and my AjaxLinks are. The AjaxLinks call an "UpdateStatus" action which changes the status of the item. After that happens the List should no longer show that item so I return the List action.

However, while the code all executes properly with no errors, the page does nt update or refresh.

Can anyone see my problem?

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

        ViewBag.Stat开发者_运维百科us = 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>


My best guess/answer so far:

It appears to have something to do with the way I'm "nesting" the return (returning the list function).

If I duplicate the List() method call inside my UpdateStatus and use the following line:

Return View("List",plvm)

It works, sort of.

Sometimes it doesn't return any data, just blanks out the entire list and leaves it there and I have to reload the entire page. Is that a bug in the ajax implementation?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜