User799396372 posted
i have used Web API Controller for poulating a select2 with departements but it's not poulating. when i use F12, i have seen in network response:
Message |
No HTTP resource was found that matches the request URI 'http://localhost:5709/api/ResultApi/?match[_type]=query&comptChargeId=&comptAnalId=&pageSize=5'. |
MessageDetail |
No action was found on the controller 'ResultApi' that matches the request.
|
there is my controller Api
public class ResultApiController : ApiController
{
UniteOfWorkBLL uniteOfWorkBll = new UniteOfWorkBLL();
//recuperer les structures paginées pour les remplire
public ResultList<ModelDto> GetStructures(string match, int? comptChargeId = null, int? comptAnalId = null, int page = 1, int pageSize = 5)
{
int totalCount;
if (page < 1)
page = 1;
if (page > 20)
page = 20;
var query = uniteOfWorkBll.StructureBLL.GetAllFiltrerdOrderedPaged(out totalCount, match, "", pageSize * (page - 1), pageSize)
.Select(s => new ModelDto
{
id = s.Id.ToString(),
text = System.Globalization
.CultureInfo.CurrentCulture
.TextInfo.ToTitleCase(s.Designation.ToLower() + "(" + s.CodeStruct + ")")
}).ToList();
return new ResultList<ModelDto> { items = query, totalCount = query.Count};
}
}
}
my java script code
$('#SelectedStructure').select2({
placeholder: "--Selectionnez--",
width: '100%',
minimumInputLength: 0,
allowClear: true,
ajax: {
url: '/api/ResultApi/',
dataType: 'json',
type: 'Get',
quietMillis: 100,
data: function (term, comptChargeId, comptAnalId, page) {
return { match: term, comptChargeId: "", comptAnalId: "" , page: page, pageSize: 5};
},
results: function (data, page) {
var more = page * 5 < data.totalCount;
return { results:data.items, page: page, more: more };
}
}
});