Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X Editable Select values loaded from MVC controller

I am having issue in loading the select options from server using x editable plugin for in place edit.Data in select option is shown as [object object] instead of actual options. Here is my code:

<a href="#" id ="status" data-name="group" data-type="select" data-source='@Url.Action("ProductGroups")' data-value="1" class="editable-click" title="Group">Operator</a>

ProductGroups action returns JSON response in following format [{"value":1,"text":"Default"}] from controller. In controller i am doing this.

public JsonResult  ProductGroups()
{
     var list = new List<xEditableItem>();
      foreach (var item in db.ProductGroups.ToList<ProductGroup>().OrderBy(r=> r.Name))
      {
         list.Add(new xEditableItem() { value = item.ID, text = item.Name });
      }
      return Json(list, JsonRequestBehavior.AllowGet);
}

public class xEditableItem { public int value {get;set;} public string text {get;set;} }

I event try passing select options manually like this but the result is the same [object object] in select list.

<a href="#" id ="status" data-name="group" data-type="select" data-source='[{"value":1,"text":"Default"}]' data-value="1" class="editable-click" title="Group">Operator</a>
like image 491
Nabeel Avatar asked Nov 12 '22 05:11

Nabeel


1 Answers

Problem might be the single quote: From

data-source='@Url.Action("ProductGroups")'

To

data-source="@Url.Action("ProductGroups")"

And you can test passing select options manually: From

data-source='[{"value":1,"text":"Default"}]'

To

data-source="[{"value":1,"text":"Default"}]"
like image 113
Vu Pham Avatar answered Nov 15 '22 06:11

Vu Pham