Note that there are some explanatory texts on larger screens.

plurals
  1. POPlease Help, Unable to access the text in MVC dropdown list on POST
    primarykey
    data
    text
    <p>I have a MVC dropdown list (Html.DropDownList) with list of Movies populated. I want to retrieve both Title(value field), Description(Text field) when I perform the form Submit. I can access the Title(value field), but I can't access the description. My code sample is below. </p> <p>//View Model.......</p> <p>public class Cinema</p> <p>{</p> <pre><code> public string CinemaName { get; set; } public SelectList MoviesList { get; set; } public string MoviesName { get; set; } </code></pre> <p>}</p> <p>public class Movie</p> <p>{</p> <pre><code> public string Title { get; set; } public string Description { get; set; } </code></pre> <p>}</p> <p>//Controller</p> <p>[AcceptVerbs(HttpVerbs.Get)]</p> <pre><code> public ActionResult Index() { Cinema _cinema = GetViewModel(); ViewData.Model = _cinema; return View(); } public IEnumerable&lt;Movie&gt; GetMovieList() { List&lt;Movie&gt; list = new List&lt;Movie&gt;(); list.Add(new Movie(){ Title = "1", Description = "Batman" }); list.Add(new Movie() { Title = "2", Description = "Metrix" }); list.Add(new Movie() { Title = "3", Description = "Jaws" }); return list; } public Cinema GetViewModel() { var cinema = new Cinema(); cinema.CinemaName = "Village"; cinema.MoviesList = new SelectList(GetMovieList(), "Title", "Description", "Jaws"); return cinema; } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Update(Cinema _cinema) { //Here I need both value and the text field from the selected item in the drop down string movieName = _cinema.MoviesName; return View(); } </code></pre> <p>//View</p> " %> <p></p> <pre><code>Home Page </code></pre> <p></p> <p></p> <pre><code>&lt;% using (Html.BeginForm("Update", "Home")) { %&gt; &lt;p&gt; To learn more about ASP.NET MVC visit &lt;a href="http://asp.net/mvc" title="ASP.NET MVC Website"&gt; http://asp.net/mvc&lt;/a&gt;. &lt;/p&gt; &lt;%= Html.TextBox("CinemaName", Model.CinemaName)%&gt; &lt;%= Html.DropDownList("MoviesName", Model.MoviesList)%&gt; &lt;input type="submit" value="Submit" /&gt; &lt;% } Html.EndForm(); %&gt; </code></pre> <p> } {</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload