Combo Box, Drop Down List in MVC using Entity Framework
Combo Box, Drop Down List in MVC 4 ASP.NET using Entity Framework>
Models Class
writer.cs
book.cs
Controller
bookController.cs
View
Create.cshtml
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)
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment