Ich möchte DropDownList verhindern, einen neuen Wert auszuwählen, aber ich möchte den vorherigen ausgewählten Wert beibehalten, wenn ich beispielsweise Informationen von einem Wert aus der Datenbank ändern möchte. $("#dropDown1").attr("disabled","disabled")
aber dies behält nicht den vorherigen Wert und meine Anwendung ist jedes Mal gebrochen, wenn ich auf diese Weise einen Vorschlag versuche?Wie deaktiviert man die Auswahl von DropDownList ASP.NET MVC?
Das ist mein Controller-Methode:
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
IQueryable<InspekcijskaKontrola> inspekcijskeKontrole = db.InspekcijskeKontrole.Include(i => i.InspekcijskaTijela).Include(i => i.Proizvod).Select(i => i);
InspekcijskaKontrola inspekcijskaKontrola = inspekcijskeKontrole.Where(i => i.InspekcijskaKontrolaId == id).Select(i => i).Single();
if (inspekcijskaKontrola == null)
{
return HttpNotFound();
}
ViewBag.InspekcijskoTijeloId = new SelectList(db.InspekcijskaTijela, "InspekcijskoTijeloId", "NazivInspekcijskogTijela", inspekcijskaKontrola.InspekcijskoTijeloId);
ViewBag.ProizvodId = new SelectList(db.Proizvodi, "ProizvodId", "NazivProizvoda", inspekcijskaKontrola.ProizvodId);
return View(inspekcijskaKontrola);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "InspekcijskaKontrolaId,InspekcijskoTijeloId,ProizvodId,DatumInspekcijskeKontrole,Rezultat,ProizvodSiguran")] InspekcijskaKontrola inspekcijskaKontrola)
{
if (ModelState.IsValid)
{
db.Entry(inspekcijskaKontrola).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.InspekcijskoTijeloId = new SelectList(db.InspekcijskaTijela, "InspekcijskoTijeloId", "NazivInspekcijskogTijela", inspekcijskaKontrola.InspekcijskoTijeloId);
ViewBag.ProizvodId = new SelectList(db.Proizvodi, "ProizvodId", "NazivProizvoda", inspekcijskaKontrola.ProizvodId);
return View(inspekcijskaKontrola);
}
Dies ist, wie ich versuchte, mit .ajax $ Informationen zu ändern, vielleicht sollte ich sagen?
$("#btnSave5").click(function (e) {
e.preventDefault();
var form = $(this).closest("form");
$.ajax({
type: "POST",
url: form.attr("Edit"),
data: form.serialize(),
success: function (response) {
alert("Informations are successfully changed");
window.location.href = "/InspekcijskeKontrole/Index";
},
error: function (error) {
alert(error);
}
});
});
Ist 'dropDown1' die ID Ihres Dropdowns? In diesem Fall ändere deine jquery in '$ (" # dropDown1 "). Attr (" disabled ", true)' – StaticBeagle
Ja, das hat mir gefallen, aber immer noch nichts war ein Fehler, als ich diese Frage trotzdem geschrieben habe. – jhony3