2014-02-16 30 views
0

我想顯示文件夾「通訊」與類別列表中的所有文件。但是當我使用下面的代碼,我有錯誤,我的代碼是:asp.net mvc下拉列表與目錄文件列表

public ActionResult templatelist() 
     { 
      var data = _session.emailForcampaigns.Select(m => m.category).Distinct().AsQueryable(); 
      ViewBag.ddlCategory = new SelectList(data, "category", "category"); 
      return View(Directory.EnumerateFiles(Server.MapPath("~/newsletter"))); 
     } 

和我有鑑於

<table class="tables" > 
    <tr> 
     <td>Fiels</td> 
     <td> 
      <select id="template" name="template"> 
      @foreach (var fullPath in Model) 
      { 
       var fileName = Path.GetFileName(fullPath); 
       <option value="@fileName"> @fileName</option> 
      } 
      </select> 
     </td> 
    </tr> 

    <tr> 
     <td>Category </td> 
     <td> 
      @Html.DropDownList("ddlCategory", null, new { @class = "dropdown " }) 
     </td> 
    </tr> 
</table> 

以下行,但我得到的錯誤

enter image description here

回答

0

您忘記指定下拉列表的數據源:

@Html.DropDownList("ddlCategory", new SelectList(ViewBag.ddlCategory , "category", "category"))