DropDownListFor with Icollections

jishui

New Member
I'm trying to add multiple Tenants to the House entity.My Error is with the drop down box (option.TenantID == Model.TenantID)I don't know how to compare an int and Icollection.Model \[code\]namespace FlatSystem.Models{[Table("House")]public class House{ [Key] public int HouseID { get; set; } public virtual ICollection<Tenants> TenantID { get; set; } public House() { TenantID = new HashSet<Tenants>(); }}}\[/code\]Controller\[code\] public ActionResult Edit(int id) { ViewBag.TenantLookupList = TenantGR.All; return View(GR.Find(id)); } // // POST: /House/Edit/5 [HttpPost] public ActionResult Edit(House house) { if (ModelState.IsValid) { GR.InsertOrUpdate(house); GR.Save(); return RedirectToAction("Index"); } return View(house); }\[/code\]Edit View\[code\] @using (Html.BeginForm("AddRole", "Role", new { houseId = @Model.HouseID })) { <table> <tr> <td>Select to Add Item</td> <td> <div class="editor-field"> @Html.DropDownListFor(model => model.TenantID, ((IEnumerable<FlatSystem.Models.Tenants>)ViewBag.TenantLookupList).Select(option => new SelectListItem { Text = (option == null ? "None" : option.Firstname), Value = http://stackoverflow.com/questions/12611785/option.TenantID.ToString(), Selected = (Model != null) && (option.TenantID == Model.TenantID) <<----Error }),"Choose...") </div> </td> <td><input type="submit" value="http://stackoverflow.com/questions/12611785/Add" /></td> </tr> </table> }\[/code\]Error\[code\]Operator '==' cannot be applied to operands of type 'int' and 'System.Collections.Generic.ICollection<FlatSystem.Models.Tenants>'\[/code\]
 
Back
Top