My Model class for Guest is
public class Guest
{
public int Regno { get; set; }
public string Company { get; set; }
public string Address { get; set; }
public virtual City City { get; set; }
}
And this is my City Model Class
public class City
{
public int Cityid { get; set; }
public string Cityname { get; set; }
}
And this is GuestController
public ActionResult New()
{
using (db)
{
IEnumerable<SelectListItem> items = db.city.Select(c => new SelectListItem
{
Value = c.Cityid.ToString(),
Text = c.Cityname
});
ViewBag.Cities = items;
}
return View();
}
This is View for New Guest
@model Hotel.Models.Guest
@Html.DropDownListFor(model=>model.City,IEnumerable<SelectListItem>ViewBag.Cities,"SelectCity",new { @class = "form-control"})
Compilation Error is showing on running of application