http://diwakarko.blogspot.com (दिवाकरको ब्लग)

Combo Box, Drop Down List in MVC using Entity Framework

No comments
Combo Box, Drop Down List in MVC 4 ASP.NET using Entity Framework>
Models Class
writer.cs
public class Writer
{
public int WriterId { get; set; }
public string WriterName { get; set; }
}


book.cs
[Bind(Exclude="bookId")]
public class book
{
public int bookId { get; set; }
[Required]
public int writerId { get; set; }
[Required]
public string title { get; set; }
public decimal price { get; set; }
public string imagepath { get; set; }
}

Controller 

bookController.cs
public ActionResult Create()
{
ViewBag.WriterId = new SelectList(db.writers, "WriterId", "WriterName");
return View();
}


View
Create.cshtml
@Html.DropDownList("WriterId",string.Empty)

No comments :

Post a Comment