Issue
Me and my clients want to move to .NET so I still didn't get it to return more than 1 vars/strings in .NET. How to return something like this in .NET?
//Verdienst für Heute ausrechnen
$clicksToCoinsToday = Click::whereIn('short_link_id', $short_link_id)->whereDate('created_at', $today)->sum('click_amount');
//Verdienst für letzte 7 Tage ausrechnen
$clicksToCoinsLast7Days = Click::whereIn('short_link_id', $short_link_id)->whereDate('created_at', '>=', $lastweek)->sum('click_amount');
return view('dashboard.admin.nutzerProfil', compact('nutzerDaten', 'clicksToCoinsYesterday', 'clicksToCoinsToday', 'clicksToCoinsLast7Days', 'allCoins'));
In C#
public ActionResult GetClicks(List<Click> clicks, string clicksCount)
{
clicks = _context.Clicks.ToList();
clicksCount = _context.Clicks.Count().ToString();
return (clicks, clicksCount);
}
I wanted to get Clicks to List and also count how many of them are in DB.
Solution
There are many ways to do this, I would recommend you should create a custom model representing the data needed for your view.
for example
public class ClicksViewModel
{
public int ClicksCount{get;set;}
public List<Clicks> Clicks{get;set;}
}
And then
return View(new ClicksViewModel(){ ClicksCount = clicksCount, Clicks = clicks });
In the view:
Model.ClicksCount;
Model.Clicks;
Answered By - Andy Song
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.