ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Populate DropDownList from Database using Entity Framework and Linq query in ASP.Net MVC<p>Hi&nbsp;nauna,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>For this example I have used of Northwind database that you can download using the link given below.</p> <p><a href="" target="_blank">Download Northwind Database</a></p> <p><strong><span style="text-decoration: underline;">Model</span></strong></p> <pre class="brush: csharp">public class DetailModel { public int Id { get; set; } public List&lt;SelectListItem&gt; Country { 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() { DetailModel model = new DetailModel(); NorthwindEntities entities = new NorthwindEntities(); model.Country = (from country in entities.Employees select new SelectListItem() { Text = country.Country, Value = country.Country }).Distinct().ToList(); return View(model); } }</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;_Populate_DropDownList_Linq.Models.DetailModel&gt;&#34; %&gt; &lt;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;;&gt; &lt;html xmlns=&#34;;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;Index&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt;&lt;%:Html.DropDownListFor(m =&gt; m.Country, Model.Country, &#34;Select&#34;, new { style = &#34;width:150px;&#34; })%&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><strong><span style="text-decoration: underline;">Sceenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="" alt="" width="254" height="134" /></span></strong></p>, 12 Jun 2019 02:56:51 GMT