Actually i had implement the multiple values jquery autocomplete textbox.if the option or item not found in the list i want to add that option to autocomplete box
Autocomplete.cshtml:
- @{
- Layout = null;
- }
- "viewport" content="width=device-width" />
Select2 with Ajax - "https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
- "https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
- class="container">class="form-group">
- ="Select Country">Select Country
- class="chose-country form-control">
Select2Model:
- public class Select2Model
- {
- public string id { get; set; }
- public string text { get; set; }
- }
HomeController:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using WebApplication3.Models;
- namespace WebApplication3.Controllers
- {
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
- return View();
- }
- public ActionResult About()
- {
- ViewBag.Message = "Your application description page.";
- return View();
- }
- public ActionResult Contact()
- {
- ViewBag.Message = "Your contact page.";
- return View();
- }
- public ActionResult autocomplete()
- {
- return View();
- }
- public ActionResult GetEmployeeList(string q)
- {
- var list = new List
(); - list.Add(new Select2Model()
- {
- text = "India",
- id = "101"
- });
- list.Add(new Select2Model()
- {
- text = "Srilanka",
- id = "102"
- });
- list.Add(new Select2Model()
- {
- text = "Singapore",
- id = "103"
- });
- if (!(string.IsNullOrEmpty(q) || string.IsNullOrWhiteSpace(q)))
- {
- list = list.Where(x => x.text.ToLower().StartsWith(q.ToLower())).ToList();
- }
- return Json(new { items = list }, JsonRequestBehavior.AllowGet);
- }
- }
- }
Actually i had implement the multiple values jquery autocomplete textbox.if the option or item not found in the list i want to add that option to autocomplete box
Please help me.
thanks && Regards
Rajanikant HawaldarPosted Dec 25, 2019, 9:22 PM