Skip to main content

ASP.Net MVC 4 + jQuery Autocomplete Dropdownlist

In this tutorial, We will show you how to make your existing dropdownlist to a automcomplete dropdownlist.
Tools used
1. Microsoft VS 2012
2. jQuery
3. jQuery-UI
4. jQuery-ui.css

Step to integrate – ASP.Net MVC 4 + jQuery Autocomplete Dropdownlist

  1. First of all, we will assume you know how to create a new MVC project in MS 2012, in case you need guide,  Please create a project and name it AutoCompleteDropDownList.
  2. After create the project, By default, jquery and jQuery-UI javascript files has been created in Scripts folder and you will see files like image below, We will need these files in later step.
    Autocomplete.
  3. Download jQuery-ui.css and save into contentthemebase folder.
    4.Download jQuery and jQuery-UI and save into Scripts folder.
  4. Go to App_start>BundleConfig.cs, and modify your code to include the downloaded jquery-ui.css
By adding new line into bundle meaning that all view will download the file even thought the page does not require the file, We assume that all of the view need this file, so that is why we include the file in bundleConfig.cs
  1. It’s recommended that we bind data with strongly type model, so that we could spot the error in design time. So we create a View Model folder and in this folder add a class name Programming.cs and this class will going to help us to bind data into view. Copy this code into Programming.cs.
  1. Create a controller named AutoCompleteDropDown. (Right click on Controllers Folder > Add > Controller). Now we need to prepare dropdownlist data , go to Controller> AutoCompleteDropDown then add this code into Index function
  1. In the AutoCompleteDropDown.cs, add view with name index. (Right click on ActionResult > Add View). Then go to Views > AutoCompleteDropDown > Index.chtml. Copy code below and paste into Index.chtml
  1. At last, Modify the _Layout.chtml, to include the css and jquery. Go to Shared > _Layout.chtml. and code in this file is look like this
You need to make sure the jQuery javascript is place on top of jQuery-UI javascript file or else Autocomplete will not work.
  1. Run the application (F5). That’s all!
    Autocomplete
The jQuery in Index.chtml it’s will help us to hide the original dropdownlist and create another fake “dropdownlist” and make it look like the original dropdownlist. In fact the actual dropdownlist is still the one which responsible to bind data from/to controller.

Comments

Popular posts from this blog

ASP .NET - XML Files

An XML File Here is an XML file named "countries.xml": <?xml version="1.0" encoding="ISO-8859-1"?> <countries> <country>   <text>Norway</text>   <value>N</value> </country> <country>   <text>Sweden</text>   <value>S</value> </country> <country>   <text>France</text>   <value>F</value> </country> <country>   <text>Italy</text>   <value>I</value> </country> </countries> Bind a DataSet to a List Control First, import the "System.Data" namespace. We need this namespace to work with DataSet objects. Include the following directive at the top of an .aspx page: <%@ Import Namespace="System.Data" %> Next, create a DataSet for the XML file and load the XML file into the DataSet when the page is first loaded: <script runat="server"> sub Page_Load if Not Page.IsPos...

Net FrameWork (Basic Concepts)

Net FrameWork (Basic Concepts) See more presentations by aSGuest51943  |  Upload your own PowerPoint presentations .Net Framework (Basic Concepts) : .Net Framework (Basic Concepts) 1 Amrita Academy For Career Excellence Overview of the .NET Framework : Overview of the .NET Framework Software development environment which helps developers to develop applications quickly and gives optimum, efficient, scalable, performance oriented applications in different languages like Visual Basic .NET, C#, ASP.NET, and Jscript .NET etc... 2 Amrita Academy For Career Excellence Slide 3: Services NET Framework provides the following services: Tools for developing software applications , run-time environments for software application to execute, server infrastructure, value added intelligent software which helps developers to do less coding and work efficiently. The .Net Framework will enable developers to develop applications for various devices and platforms like window...

Crystal and Reporting Services Interview Questions - Part 2

Introduction   This FAQ will give you a quick start for two report giant's crystal and reporting services. We have two IIS application 'Reports' and 'Reportserver' what do they do ?   When you install reporting services there are two virtual directories created as shown in the figure below. Figure : - IIS Applications for reports The 'Reports' virtual directory is like an admin. If you browse to http://yourpcname/reports/home.aspx   page you can view, edit properties and display reports. We have numbered the below figure. 1 à We can browse reports and see the output of reports. 2 à We can upload a RDL file directly in the report's database. 3 à Using the report builder link we build new reports. 4 à Using the properties we can do role assignment. 5 à Using subscription link we can add new outputs (FTP, Folder etc) to subscribe to the reports. 6 à Site settings help us to decide how many numbers of snapshots we want in the history, report time out...