2012-01-05 10 views
0

私は学習しています.Net MVC。私は製品ラインを示すページを持っています。ドロップダウンリストを使用して、サプライヤによって製品ラインをフィルタリングしたいと思います。ビューがリフレッシュされないのはなぜですか? (.Net MVC)

マイコントローラ:

public class ProductlineController : Controller 
{ 
    SupplierRepository sr = new SupplierRepository(); 
    ProductlineRepository pr = new ProductlineRepository(); 

    public ActionResult Default() 
    { 
     SupplierModel sm = new SupplierModel(); 

     List<Supplier> suppliers = sr.GetAll(); 

     sm.Suppliers = (from s in suppliers select new SelectListItem { 
     Text = s.Name, 
     Value = s.Id.ToString() 
     }).ToList(); 

     sm.Productlines = pr.GetAll(); 

     return View("List", sm); 
    } 

    [HttpPost] 
    public ActionResult SupplierDropUsed(int id) 
    { 
     SupplierModel sm = new SupplierModel(); 

     List<Supplier> suppliers = sr.GetAll(); 

     sm.Suppliers = (from s in suppliers 
         select new SelectListItem 
         { 
          Text = s.Name, 
          Value = s.Id.ToString() 
         }).ToList(); 

     Supplier supplier = sr.GetById(id); 
     sm.Productlines = supplier.Productlines.ToList(); 

     return View("List", sm); 
    } 
} 

デフォルトのアクションはすべてproductlinesを示しています。 SupplierDropUsedは、ドロップダウンリストが変更されたときに呼び出されます。

ビュー:{ レイアウト=ヌル@

@model RyfMvcTestApplication1.Models.SupplierModel 

。 }

リスト

<script type="text/javascript"> 

    function supplierDropChanged() { 

     $.post("Productline/SupplierDropUsed", { id: $('#SupplierDrop').val() }); 
    } 

</script> 

<div><strong>Filter by supplier</strong></div> 
<br /> 

<div> 

@Html.DropDownList("SupplierDrop", Model.Suppliers, "Select supplier", new { onChange = "supplierDropChanged()" }) 

</div> 
<br /> 
<br /> 

<table> 
    <tr> 
     <th style="width:50px; text-align:left">Id</th> 
     <th style="text-align:left">Name</th> 
     <th style="text-align:left">Supplier</th> 
    </tr> 

@foreach (var item in Model.Productlines) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.Id) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Name) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Supplier.Name) 
     </td>    
    </tr> 
} 

</table> 

Iはサプライヤーを選択すると、JavaScriptとコントローラのアクションは、(Iデバッグモードでチェック)が実行されます。私はまた正しいサプライヤーIDを取得します。しかし、その見解は決してリフレッシュされません。私はまだすべての製品ラインのリストを参照してください。

答えて

0

リクエストを送信するjquery postメソッドを使用してポストを行っているため、デバッグアクションが呼び出されたがポストコールから返された結果はUIを更新するために使用されることはありません。

+0

問題を説明するだけではありませんか? – SteveCav

関連する問題