2012-01-17 13 views
0

私は私のモデルでこれを持っているが、内容は国の完全なリストでありますリストと選択された値。設定DropDownListFor

@Html.DropDownListFor(c => c.LookupCountry.Id, 
    new SelectList(Model.LookupCountry, 
    "Id", 
    "Value", 
    Model.SelectedCountry), 
    "-- Select Country --") 

私はこれを行うと、私はエラーが備わってい、c => c.LookupCountry.Id同上は、ビューでは使用できません。

おかげで、トリックを行う必要がありますc.LookupCountry.Idc.SelectedCountryに変更

答えて

0

。 LookupCountry以来、国のコレクションにはIdプロパティがありません。ドロップダウンから選択した値をSelectedCountryプロパティにバインドしたいとします。モデル内のLookupCountryIList<LookupCountry>の種類があるためである

@Html.DropDownListFor(c => c.SelectedCountry, 
    new SelectList(Model.LookupCountry, 
    "Id", 
    "Value", 
    Model.SelectedCountry), 
    "-- Select Country --") 
0

。全リストにはidが含まれておらず、そのメンバーすべてが1つずつidを含んでいます。おそらく、次のようにメソッドを書き直したいと思うでしょう。

@Html.DropDownListFor(c => c.SelectedCountry, 
    new SelectList(Model.LookupCountry, 
    "Id", 
    "Value", 
    Model.SelectedCountry), 
    "-- Select Country --") 
関連する問題