ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
how to get selected text from ajaxdropdown?
Title:
B
I
{code}
?
how to get selected text from ajaxdropdown in the: [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create of the controller. my AjaxDropdown gets data from this action: public ActionResult GetEmpresas() { var ret = db.FLG_Empresas.Where(x => x.RegistrateID == User.Identity.Name).Select(x => new { x.RegistrateID, x.IdEmpresa, x.Empresa }).ToList(); if (ret.Count != 0) { var items = ret.Select(o => new KeyContent(o.IdEmpresa, o.Empresa)); return Json(items); } else return Json(new List<SelectableItem>{ new KeyContent(0, "No no hay empresas registradas") }); } Can you give me an example please? I am new to working with MVC and your product.
Save Changes
Cancel
Juan Equiz
asked at 13 Aug 2015
Answers
B
I
{code}
?
since you're new to MVC I recommend this tutorial first: https://www.youtube.com/watch?v=fsfOFL4bXXA after try this: in your view you have something like this: @Html.Awe().AjaxDropdown("IdEmpresa").Url(... viewmodel: public class CreateViewModel { public int? IdEmpresa { get; set; } } and in the controller: public ActionResult Create(CreateViewModel input) { var selected = db.FLG_Empresas.Where(o => o.IdEmpresa = input.IdEmpresa).FirstOrDefault(); var text = ""; if(selected != null){ text = selected.Empresa } ... }
Save Changes
Cancel
Omu
answered at 14 Aug 2015
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK