Hi,
I have a dropdown list for my report to choose an option and based on the option i will generate the code that. clicking the submit button is not doing anything.
index.cshtml
<label class="from-label">Reports</label>
<hr />
@Html.DropDownList("options",
ViewBag.options,
"Select an option",
new {@class="form-control"})
and this is the controller (now it is only for 7 days just testing why its not fired when the button is clicked):
public async Task<ActionResult> Index()
{
//Last 7 days
DateTime StartDate = DateTime.Today.AddDays(-6);
DateTime EndDate = DateTime.Today;
List<Transaction> SelectedTransactions = await _context.Transaction
.Include(x => x.Category)
.Where(y => y.Date >= StartDate && y.Date <= EndDate)
.ToListAsync();
// total income
int TotalIncome = SelectedTransactions
.Where(i => i.Category.Type == "Income")
.Sum(j => j.Amount);
ViewBag.TotalIncome = TotalIncome.ToString("C0");
// total expense
int TotalExpense = SelectedTransactions
.Where(i => i.Category.Type == "Expense")
.Sum(j => j.Amount);
ViewBag.TotalExpense = TotalExpense.ToString("C0");
// Balance
int Balance = TotalIncome - TotalExpense;
CultureInfo culture = CultureInfo.CreateSpecificCulture("ae-AE");
culture.NumberFormat.CurrencyNegativePattern = 1;
ViewBag.Balance = String.Format(culture, "{0:C0}", Balance);
return View();
}
how to take the choosen option (for example "Last 7 days" into the controller page and use it in an if statement: