Reputation:
I have js code where I pass data to repo method via parameters.
Here is repo method:
public List<SpeedLimitViewModel> GetSpeedData(decimal imei, DateTime start, DateTime end)
{
using (TraxgoDB ctx = new TraxgoDB())
{
List<SpeedLimitViewModel> alldata = new List<SpeedLimitViewModel>();
var alllogs = ctx.Logging.OrderByDescending(x => x.LogID).ToList();
for (int i = 1; i < alllogs.Count; i++)
{
alldata.Add(new SpeedLimitViewModel
{
Imei= alllogs[i].Imei,
Latitude2 = alllogs[i].Latitude,
Longitude2 = alllogs[i].Longitude,
Speed = alllogs[i].Speed
});
}
return alldata;
}
}
And I call this method in controller like this:
public JsonResult SpeedData()
{
var speeddata = repoEntities.GetSpeedData();
return Json(speeddata.ToArray(), JsonRequestBehavior.AllowGet);
}
But I have error
Severity Code Description Project File Line Suppression State Error CS7036 There is no argument given that corresponds to the required formal parameter 'imei' of 'ReportsRepositoryEntities.GetSpeedData(decimal, DateTime, DateTime)' Traxgo.TrackerWeb C:\Users\EugeneSukhomlyn\Source\Workspaces\TraxgoWeb\Traxgo.TrackerWeb\Controllers\ReportsController.cs 94 Active
Where is my problem?
Upvotes: 3
Views: 96
Reputation: 44
You need to remove paramteres for your functions or you need to set default values in method definition like Paweł mentioned, or finally you can overload your method defitinion to the version with and without parameters.
Upvotes: 0
Reputation: 3586
Your method looks like that:
GetSpeedData(decimal imei, DateTime start, DateTime end)
Yet you are calling it like that:
GetSpeedData()
Also I don't see you are using imei
or start
or end
anywhere in your method, so you should probably remove them from your method definition
So you should pass parameters to your function, probably from your controller method like so:
public JsonResult SpeedData(decimal imei, DateTime start, DateTime end)
{
var speeddata = repoEntities.GetSpeedData(imei, start, end);
return Json(speeddata.ToArray(), JsonRequestBehavior.AllowGet);
}
Or maybe the parameters will not come from controller method, but from somewhere else - does not matter, in your current design you will have to pass defined parameters to your GetSpeedData function.
Or you can define your function like that (using optional parameters):
public List<SpeedLimitViewModel> GetSpeedData(decimal imei = 0, DateTime start = new DateTime(), DateTime end = new DateTime())
{
}
And you will be able to call it even by calling GetSpeedData()
(all the parameters will have values provided as default values for optional parameters)
Upvotes: 3
Reputation: 721
public JsonResult SpeedData(decimal imei, DateTime start, DateTime end)
{
var speeddata = repoEntities.GetSpeedData(imei, start, end);
return Json(speeddata.ToArray(), JsonRequestBehavior.AllowGet);
}
Upvotes: 3