I have 2 classes Book & designation in model folder
Here i am inherting Designation class in book
namespace MvcApplication2.Models{
public class Book
{
public int SelectedDESIGNATION_ID { get; set; }
[Required]
[StringLength(5,ErrorMessage="Length Exceeding")]
public string NAME { get; set; }
public List<designation> Designation { get; set; }
// public List<SelectListItem> Designation { set; get; }
// public int SelectedCity { set; get; }
}
}
namespace MvcApplication2.Models
{
public class Designation
{
public int DESIGNATION_ID { get; set; }
public string DESIGNATION_NAME { get; set; }
}
}
My controller-
public ActionResult BookDetails()<br />
{<br />
Book book = new Book();<br />
book.NAME = "alpa";<br />
book.Designation = new List<Designation>();<br />
book.Designation = GetDesignation();<br />
return View(book);<br />
}
private List<Designation> GetDesignation()<br />
{<br />
List<Designation> DList = new List<Models.Designation>();<br />
Designation des = new Designation();<br />
des.DESIGNATION_NAME = "dcos";<br />
des.DESIGNATION_ID = 1;<br />
<br />
des = new Designation();<br />
des.DESIGNATION_ID = 2;<br />
des.DESIGNATION_NAME = "jen";<br />
DList.Add(des);<br />
return DList;<br />
}<br />
My View-
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication2.Models.Book>" %><br />
<br />
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"><br />
BookDetails<br />
</asp:Content><br />
<br />
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"><br />
<br />
<h2>BookDetails</h2><br />
<br />
<% using (Html.BeginForm()) { %><br />
<%: Html.LabelFor(m => m.NAME) %><br />
<div class="editor-field"><br />
<%: Html.TextBoxFor(m => m.NAME) %><br />
<%: Html.ValidationMessageFor(m => m.NAME) %><br />
</div><br />
<%: Html.LabelFor(m => m.Designation) %><br />
<div><br />
<%: Html.DropDownList("Designation", new SelectList(Model.Designation, "DESIGNATION_ID", "DESIGNATION_NAME",""))%><br />
<br />
</div><br />
<br />
<br />
<div><br />
<input type="submit" value="Book" /><br />
</div><br />
<% } %><br />
</asp:Content><br />
Till here My dll is populating But I want to get value of selected DLL VALUE IN CONTROLLER on clicking of button
[HttpPost]<br />
public ActionResult BookDetails(Book model)<br />
{<br />
var name = model.NAME;<br />
}