2017-03-31 54 views
0

這是另一個問題的分支。我將一個列表傳遞給作爲主視圖一部分的部分視圖。然而,當我查看網頁,我看到:現在作爲字符串的HTML呈現模型

System.Collections.Generic.List`1[...Models.OutcomeArea] List 

,列表被正確渲染,但我不知道爲什麼上面的線是在HTML顯示。

Index.cshtml:

@using (Html.BeginForm("Index", "Search", FormMethod.Get, new { @class = "form-inline" })) 
{ 
    @Html.Action("_Checklist") 
} 

_Checklist.cshtml:

@Model List<....Models.OutcomeArea> 
<div class="row"> 
    <div class="col-md-4"> 
     <h4 class="text-center">Outcomes</h4> 
     <p> 
     @foreach (var list in Model) 
     { 
      <input type="checkbox" id="@list.ID" name="@list.ID" /> @list.Category <br /> 
     } 
     </p> 
    </div> 
</div> 

SearchController:

public PartialViewResult _Checklist() 
    { 
     var outcomeAreas = db.OutcomeArea.Where(oa => oa.Category != "").GroupBy(oa => oa.Category).Select(oa => oa.FirstOrDefault()); 
     return PartialView("_Checklist", outcomeAreas.ToList()); 
    } 
+0

在HTML中它顯示它的位置?什麼是渲染輸出? – David

+0

字符串的第一部分看起來像來自List <.... Models.OutcomeArea>對象的標準'ToString()'。 –

回答

0

沒關係,我有工作。我需要爲_Checklist.cshtml使用小寫的@model。

@model List<....Models.OutcomeArea> 
0

哇。花了一段時間來發現錯誤。狡猾的一個,這個。您的型號聲明是問題:

@Model List<....Models.OutcomeArea> 

那應該是@model,小寫。你現在的字面意思是打印出Model

相關問題