2

外部データベーステーブルからチェックボックスのリストをレンダリングしようとしていますが、このエラーが発生し続けます: タイプ 'int' を 'bool' に暗黙的に変換できません

リストを返す強く型付けされたビューの幸せな b/c ではないと推測しています。誰でも助けてください。前もって感謝します。

私のモデル

public partial class tblCity
{
    public int ID { get; set; }
    public string Name { get; set; }
    public int IsSelected { get; set; }
} 

私の見解

@model List<Demo.Models.Sample>    

@for (int i = 0; i < Model.Count; i++)
{    
   @Html.CheckBoxFor(m => m[i].ID)  **Cannot implicitly convert type 'int' to 'bool'**
}
4

1 に答える 1

1

これは、int を与えているためです。

@for (int i = 0; i < Model.Count; i++)
{    
   @Html.CheckBoxFor(m => m[i].ID) <- ID is an Int
}

ブール値を与える必要があります。おそらく、IsSelected は bool であるはずだったのですが、それがあなたが探していたものでしたか?

public partial class tblCity
{
    public int ID { get; set; }
    public string Name { get; set; }
    public bool IsSelected { get; set; }
} 

次に、ビュー

@model List<Demo.Models.Sample>    

@for (int i = 0; i < Model.Count; i++)
{    
   @Html.CheckBoxFor(m => m[i].IsSelected )
}
于 2014-08-05T16:37:43.143 に答える