Hello Team,
In my product mvc C# I 'm using bootrstrap select2 for fetching category from category table and inserting the data into product table, but nothing seems to be working, any assistance will be appreciated.
<div class="col-md-4"> <div class="form-group" id="txtdvCategory"> <label>Select Category<small class="text-muted">-- </small></label> <select class="select2 form-control custom-select" style="width: 100%; height:36px;"> <option>Select </option> <optgroup label="Item List"> <option value="HL"></option> <option value="KL"></option> </optgroup> </select> </div> </div>
$("#txtdvCategory").select2({ //minimumInputLength: 1, tags: [], ajax: { url: "/POS/getAllCategory", dataType: 'json', type: "GET", quietMillis: 50, data: function (term) { return { term: term }; }, results: function (data) { return { results: $.map(data, function (item) { return { text: item.CategoryName, slug: item.slug, id: item.CategoryId } }) }; } } });
public JsonResult getAllCategory() { var dataList = objHotelDbEntities.tblCategories.ToList(); var modifiedData = dataList.Select(x => new CategoryViewModel { CategoryId = x.CategoryId, CategoryName = x.CategoryName }).ToList(); return Json(modifiedData, JsonRequestBehavior.AllowGet); }