0

I am just starting on MVC so this should be an easy question to answer. I am using MVC 2 for ASP.Net. I have a drop down list which when changes should cause the grid to change as well. I have found a way to catch the change selection event and refresh the whole form using the code below. The $('#TheForm').submit(); command causes the Index method of the Controller to run, and resets everything back as before. What I want of course is for this method to pick up the new value of the dropdownlist, extract and display the new data in the View accordingly. Is this how I should do it, or should I do more on the client side instead?

$(function () { $("#StatusId").change(function () { $('#TheForm').submit(); }); });

<p>
    <% using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "TheForm" })){%>
        <%: Html.DropDownList("StatusId", (SelectList) ViewData["Status"]) %>
    <%}%>
</p>

<p>
    <% if (Request.IsAuthenticated) {  %>
     <%:  Html.ActionLink("Add new item", "Add")  %>
    <% }  %>
</p>

<table>
    <tr>

        <th>
            Title
        </th>

        <th>
            Date
        </th>
        <th>
            Status
        </th>
    </tr>

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

    <tr>


        <td>
            <%: Html.ActionLink(item.Title, "Details", new { id = item.ItemCode }) %>
        </td>

        <td>
            <%: String.Format("{0:g}", item.DateCreated) %>
        </td>
        <td>
            <%: item.Status %>
        </td>
    </tr>

<% } %>

</table>

  <p>
    <%: Html.Label("Page: ") %>

    <% for (int i = 1; i < Convert.ToInt32(ViewData["NumberOfPages"]); i++)
       {  %>

    <%: Html.ActionLink(i.ToString(), "Index", new { page = i })%>

    <% }  %>

  </p>

1 Answer 1

1

The Index action needs a parameter StatusId.

It has to filter the list of items by StatusId. If this does not work please post the code of the action.

Sign up to request clarification or add additional context in comments.

1 Comment

Spot on. I really needed to learn that, even though the answer was very simple in the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.