Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "results": [
- {
- "id": 1,
- "text": "Option 1"
- },
- {
- "id": 2,
- "text": "Option 2"
- }
- ],
- }
- public class Select2
- {
- public int id { get; set; }
- public string text { get; set; }
- }
- [HttpGet]
- public async Task<ActionResult> GetMesa(string q)
- {
- try
- {
- if (String.IsNullOrEmpty(q) || String.IsNullOrWhiteSpace(q))
- {
- return Json(new { });
- }
- else
- {
- List<Mesa> mesas = await db.Mesa.Where(x => x.NombreMesa.ToLower().StartsWith(q.ToLower())).ToListAsync();
- List<Select2> items = new List<Select2>();
- foreach(var mesa in mesas)
- {
- Select2 item = new Select2() {
- id = mesa.MesaID,
- text = mesa.NombreMesa
- };
- items.Add(item);
- }
- return Json(new { items = items },JsonRequestBehavior.AllowGet);
- }
- }
- catch (Exception e)
- {
- return Json(new {respuesta = "MesasController => GetMesa n" + e.Message + e.InnerException});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement