views:

34

answers:

0

First, some code:

Here is the initial Action that is called when the page is navigated to:

public ActionResult ListCodeTypes()
{
    var CodeList = _entities.Master_Codes.ToList();

    List<SelectListItem> items = new List<SelectListItem>();
    for (int i = 0; i < CodeList.Count; i++)
    {
        items.Add(new SelectListItem { 
            Text = CodeList[i].description, 
            Value = CodeList[i].code_table_name 
        });
    }

    ViewData["items"] = items;
    return View("CodesAdmin");
}

Here is the CodesAdmin aspx page/view code:

<%@ Page Title="" Language="C#" 
    MasterPageFile="~/Views/Shared/Site.Master"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
CodesAdmin
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% Html.RenderPartial("subMenu/ParcelSubMenu"); %>
    <h2>CodesAdmin</h2>
    <%= Html.DropDownList("items")%>
    <input type="button" id="btnGetCodes" name="GetCodes" 
        value="Get Codes" class="fg-button ui-state-default appButton"
        onclick="searchClick()"/>
    <div id="CodeAdminPlaceHolder"></div>
    <script type="text/javascript">
        function searchClick() {
            var searchText = $("#items").val();
            $.get("/Admin/CodeListing/", 
                { identifier: searchText }, function (data) {  
                    $("#CodeAdminPlaceHolder").html(data); 
                }, "html");
        }
    </script>
</asp:Content>

Now, here is the controller code that is called from the button click:

public ActionResult CodeListing(string identifier)
{
    _entities.Refresh(System.Data.Objects.RefreshMode.StoreWins,
        _entities.Address_Type_Codes);

    var CodeList = _entities.Address_Type_Codes.
        Where(p=>p.active == true).ToList();

    return PartialView("ListOfAddrCodes", CodeList);
}

The CodeListing action actually handles multiple inputs depending on the "identifier" parameter.

The resulting partial view, rendered in the "CodeAdminPlaceHolder" div is:

<div id="Div15"  class="ui-widget-content">
    <table id="CodeListing" class="tablesorter">
        <thead>
            <tr>
                <th></th>
                <th>
                    Short Description
                </th>
                <th>
                    Long Description
                </th>
                <th>
                    Active
                </th>
                <th>
                    Tax Year
                </th>
                <th>
                    Note
                </th>
            </tr>
        </thead>

        <tbody>
            <% foreach (var item in Model) { %>

                <tr>
                    <td>
                        <%= Html.ActionLink("Deactivate", 
                            "DeactivateAddrCode", new { 
                                id=item.address_type_codes_id 
                             }) %>
                    </td>
                    <td>
                        <%: item.short_description %>
                    </td>
                    <td>
                        <%: item.long_description %>
                    </td>
                    <td>
                        <%: item.active %>
                    </td>
                    <td>
                        <%: item.tax_year %>
                    </td>
                    <td>
                        <%: item.note %>
                    </td>
                </tr>

            <% } %>
        </tbody>

        <tfoot>
            <tr id="pager">
                <td colspan="6">
                    <img src="/Content/TableSorter/Themes/Default/first.png"
                        class="firstPage" alt="First" />
                    <img src="/Content/TableSorter/Themes/Default/prev.png" 
                        class="prevPage" alt="Prev"/>
                    <input type="text" class="pagedisplay"/>
                    <img src="/Content/TableSorter/Themes/Default/next.png" 
                        class="nextPage" alt="Next"/>
                    <img src="/Content/TableSorter/Themes/Default/last.png" 
                        class="lastPage" alt="Last"/>
                    <select class="pagesize">
                        <option selected="selected" value="5">5</option>
                        <option value="10">10</option>
                        <option value="15">15</option>
                        <option  value="20">20</option>
                    </select>
                </td>
            </tr>
        </tfoot>
    </table>
</div>

If someone clicks the "Deactivate" Link, this action is called:

public ActionResult DeactivateAddrCode(int id)
{
    Address_Type_Codes ac1 = _entities.Address_Type_Codes.
        First(c => c.address_type_codes_id == id);

    ac1.active = false;
    _entities.Refresh(System.Data.Objects.RefreshMode.ClientWins, 
        _entities.Address_Type_Codes);

    UpdateModel(ac1);

    _entities.SaveChanges();

    return RedirectToAction("ListCodeTypes");
}

This loads the page back to the beginning with the dropdown box and the button.

The problem is that, when I click the button to load up the address types, it does not call the "CodeListing" controller action. I verified this by putting a breakpoint in the "CodeListing" code and, sure enough, the code does not get called. Therefore, when a choice is made in the dropdown list and the button is clicked, it shows invalid data. If I stop and restart the app in VS, the data lists correctly.

The CodeListing action gets called once only and I guess the cached page is returned.

We're using the entity framework for Data Access but I don't think our problems have anything to do with this.