ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Get DropDownList selected Text in Controller in ASP.Net MVC <p>I will get back to you soon.</p>https://www.aspforums.net:443/Threads/162607/Get-DropDownList-selected-Text-in-Controller-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/162607/Get-DropDownList-selected-Text-in-Controller-in-ASPNet-MVC/Sun, 16 Jun 2019 23:56:25 GMTGet DropDownList selected Text in Controller in ASP.Net MVC <p>Hi Anton,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Model</span></strong></p> <pre class="brush: csharp">public class ViewModel { public int PositionId { get; set; } [System.ComponentModel.DisplayName(&#34;Position&#34;)] public string PositionName { get; set; } }</pre> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { // GET: /Home/ public ActionResult Index() { return View(new ViewModel()); } [HttpPost] public ActionResult Load(ViewModel model) { List&lt;DepPosition&gt; positionList = GetPositions(); DepPosition positionName = positionList.Find(p =&gt; p.PositionId == model.PositionId); model.PositionName = positionName.PositionName; ViewData[&#34;SelectedPosition&#34;] = model.PositionName; return View(&#34;Index&#34;, new ViewModel()); } public List&lt;DepPosition&gt; GetPositions() { // Get data from Database. List&lt;DepPosition&gt; positionList = new List&lt;DepPosition&gt;(); positionList.Add(new DepPosition { PositionId = 1, PositionName = &#34;Software Developer&#34; }); positionList.Add(new DepPosition { PositionId = 2, PositionName = &#34;Tester&#34; }); positionList.Add(new DepPosition { PositionId = 3, PositionName = &#34;Software Engineer&#34; }); return positionList; } public ActionResult GetPositionList() { return Json(GetPositions(), JsonRequestBehavior.AllowGet); } public class DepPosition { public int PositionId { get; set; } public string PositionName { get; set; } } }</pre> <p><strong><span style="text-decoration: underline;">View</span></strong></p> <pre class="brush: html">&lt;%@ Page Language=&#34;C#&#34; Inherits=&#34;System.Web.Mvc.ViewPage&lt;ViewModel&gt;&#34; %&gt; &lt;%@ Import Namespace=&#34;Transfer_Through_JSON_MVC.Models&#34; %&gt; &lt;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Index&lt;/title&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(document).ready(function () { $.get(&#34;/Home/GetPositionList&#34;, function (data) { $(&#34;#PositionId&#34;).empty(); $(&#34;#PositionId&#34;).append(&#34;&lt;option value=&#39;0&#39;&gt;--Select Position--&lt;/option&gt;&#34;) $.each(data, function (index, row) { $(&#34;#PositionId&#34;).append(&#34;&lt;option value=&#39;&#34; + row.PositionId + &#34;&#39;&gt;&#34; + row.PositionName + &#34;&lt;/option&gt;&#34;) }); }) }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;%using (Html.BeginForm(&#34;Load&#34;, &#34;Home&#34;, FormMethod.Post)) {%&gt; &lt;div class=&#34;form-group&#34;&gt; &lt;%:Html.LabelFor(model =&gt; model.PositionName)%&gt; &lt;%:Html.DropDownListFor(model =&gt; model.PositionId, new SelectList(&#34;&#34;), &#34;--Select Position--&#34;, new { @class = &#34;form-control&#34; })%&gt; &lt;/div&gt; &lt;input type=&#34;submit&#34; value=&#34;Save&#34; /&gt; &lt;% } %&gt; &lt;%if (ViewData[&#34;SelectedPosition&#34;] != null) {%&gt; Selected position is : &lt;%=ViewData[&#34;SelectedPosition&#34;] %&gt; &lt;%} %&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/5DVuG29.gif" alt="" width="281" height="188" /></span></strong></p>https://www.aspforums.net:443/Threads/162607/Get-DropDownList-selected-Text-in-Controller-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/162607/Get-DropDownList-selected-Text-in-Controller-in-ASPNet-MVC/Mon, 17 Jun 2019 08:43:38 GMTGet DropDownList selected Text in Controller in ASP.Net MVC <p>I have modified the reply with sample. Refer below link.</p> <p><a href="https://www.aspforums.net/Threads/162607/Find-Name-by-its-Id/Replies/2#Replies">https://www.aspforums.net/Threads/162607/Find-Name-by-its-Id/Replies/2#Replies</a></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/162607/Get-DropDownList-selected-Text-in-Controller-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/162607/Get-DropDownList-selected-Text-in-Controller-in-ASPNet-MVC/Tue, 18 Jun 2019 01:39:18 GMT