Click here to Skip to main content
15,887,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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<SelectListItem>();<br />
           book.Designation = new List<Designation>();<br />
         //book.Designation = GetDesignation();<br />
           book.Designation = GetDesignation();<br />
         //ViewData["book.Designation.DESIGNATION_NAME"] = 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 />
           // var des = model.Designation.FirstOrDefault().Value;---><big>Want to get value of designation id</big>            return View(model);<br />
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900