2010-06-08 43 views
0

我剛剛開始使用MVC,所以這應該是一個容易回答的問題。 我正在使用MVC 2 ASP.Net。 我有一個下拉列表,當更改應該導致網格也改變。 我找到了一種方法來捕獲更改選擇事件並使用下面的代碼刷新整個表單。 $('#TheForm')。submit();命令導致Controller的Index方法運行,並像以前一樣重置所有內容。 我想要的當然是這個方法獲取下拉列表的新值,相應地在視圖中提取並顯示新數據。 這是我應該怎麼做的,還是應該在客戶端做更多的事情?ASP.Net MVC 2 - 控制網格的下拉列表

$(函數(){ $( 「#StatusId」)改變(函數(){ $( '#TheForm')提交(); }); });

<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

索引操作需要一個參數StatusId。

它必須通過StatusId篩選項目列表。如果這不起作用,請發佈操作的代碼。

+0

現貨。儘管最終答案非常簡單,但我確實需要了解這一點。 – arame3333 2010-06-08 12:58:37