1
我對我的視圖有問題,對於HTTP POST,視圖模型對於我的所有屬性返回null
。MVC3的POST模型屬性爲空
以下是我的觀點模型。
public class CustomerVM
{
public List<CustomerCDTO> customerCDTO { get; set; }
}
在上述視圖模型我已經創建了一個List<CustomerCDTO>
屬性。 CustomerCDTO
類的定義如下。
public class CustomerCDTO
{
public string Name { get; set; }
public bool Active { get; set; }
public bool? IsChecked { get; set; }
}
下面是我的看法:
<%foreach (var item in Model.customerCDTO) {%>
<tr>
<td style="text-align: center; width: 10%;" class="table-content-middle">
<%if (item.Active == true)
{%>
<%=Html.CheckBoxFor(m=>item.Active)%>
<%}
else
{ %>
<%=Html.CheckBoxFor(m=>item.Active)%>
<%}%>
</td>
<td class="table-content-middle" align="center" style="width: 80%;">
<%: item.Name%>
</td>
</tr>
<%} %>
當我執行HTTP GET一切正常,但在POST我收到null
爲CustomerVM.customerCDTO
。
請建議我該怎麼做才能使它工作。
感謝,
謝謝jon其工作正常。 – aamankhaan
大家好,它對我的<%= Html.CheckBoxFor(m => item.Active)%>工作正常,但它不給我爲null <%:item.Name%> ...請建議 – aamankhaan
@aamankhaan :什麼是「物品」?答案中沒有這樣的變量。 – Jon