public class VersionController : ApiController
{
[HttpGet]
public List<AutoCompleteCompany> acCompany(string term)
{
DataSet ds = new DataSet();
List<AutoCompleteCompany> co= new List<AutoCompleteCompany>();
try
{
ds = getdetails(term);//privae method returns dataset
co = ds.Tables[0].ToList<AutoCompleteCompany>();
}
catch (Exception ex)
{
}
return co;
}
}
Properties below
public class AutoCompleteCompany
{
public string Value { get; set; }
}
Converts dataset to list
public static List<T> ToList<T>(this DataTable table) where T : new()
{
IList<PropertyInfo> properties = typeof(T).GetProperties().ToList();
List<T> result = new List<T>();
foreach (var row in table.Rows)
{
var item = CreateItemFromRow<T>((DataRow)row, properties);
result.Add(item);
}
return result;
}
private static T CreateItemFromRow<T>(DataRow row, IList<PropertyInfo> properties) where T : new()
{
T item = new T();
foreach (var property in properties)
{
if (property.PropertyType == typeof(System.DayOfWeek))
{
DayOfWeek day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), row[property.Name].ToString());
property.SetValue(item, day, null);
}
else
{
if (row[property.Name] == DBNull.Value)
property.SetValue(item, null, null);
else
property.SetValue(item, row[property.Name], null);
}
}
return item;
}
Webapiconfig
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(name: "DefaultApi",
routeTemplate: "Api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
Error:
No HTTP resource was found that matches the request
MessageDetail: no action was found on the controller 'AutoComplete' that matches the request.
and below custom method works
public string GetAccess(string id)
{
return "value3";
}
Please suggest a way to return dataset from stored procedure in to json as result (web api rest)
MessageDetail: no action was found on the controller 'AutoComplete' that matches the request.?