Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
In my Asp.net Mvc 5.0 project, how to disable auto-complete for Select City DropDown?

i did not added autofill option for auto selecting city from the dropdown. if i run app without selecting city. it gives an alert as "select city", but if we back to select city, there is a city which is already selected, How it is possible ? i have given the code below for the reference...

any suggesation or solution is appriciable. Thank You

this is the ASP.NET rozar :
<div class="col-md-9">
  <label>City</label><span class="text text-danger">*</span> @{ if (ViewBag.cityId != null) { @Html.DropDownList("cityId", null, "--Select City--", new { @id = "ddlCity", @class = "form-control" }) } else { @Html.DropDownList("cityId", new List
  <SelectListItem>(), "--SelectCity--", new { @id = "ddlCity",@class = "form-control" }) } } @Html.ValidationMessageFor(model => model.cityId, "", new { @class = "text-danger" })
</div>

// error message

if ($("#ddlcity").val() == "" || $("#ddlcity").val() == null) {
            alert('Please Select city')
            return false;
        }

MVC method to get list of states :

public JsonResult GetStateWiseData(string stateId) {
  var stId = stateId.Split('_');
  List < SelectListItem > pClassList = new List < SelectListItem > ();
  if (stId[0] == "#") {
    var objactvt = db.cities.Where(x => x.top == true).ToList();

    objactvt.ForEach(x => {
      pClassList.Add(new SelectListItem {
        Text = x.cityName, Value = x.cityId.ToString()
      });
    });
  } else {
    int stid = Convert.ToInt32(stId[0]);
    var btn = stId[1];
    List < city > objactvt;
    if (btn == "0") {
      for (int i = 0; i <= 9; i++) {
        objactvt = db.cities.Where(x => x.cityName.StartsWith(i.ToString()) && x.stateId == stid).ToList();
        objactvt.ForEach(x => {
          pClassList.Add(new SelectListItem {
            Text = x.cityName, Value = x.cityId.ToString()
          });
        });
      }
    } else {
      objactvt = db.cities.Where(x => x.cityName.StartsWith(btn) && x.stateId == stid).ToList();


      objactvt.ForEach(x => {
        pClassList.Add(new SelectListItem {
          Text = x.cityName, Value = x.cityId.ToString()
        });
      });
    }
  }
  return Json(pClassList.OrderBy(x => x.Text), JsonRequestBehavior.AllowGet);

}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda