Quote:Nullable object must have a value.
@{ var fromPrice = ViewBag.fromPrice as Decimal?; var toPrice = ViewBag.toPrice as Decimal?; } @using (Html.BeginForm("FiltredPrice", "Home", FormMethod.Get)) { <div>From Price: @Html.TextBox("fromPrice", fromPrice.Value))</div> <div>To Price: @Html.TextBox("toPrice", toPrice.Value))</div> <input type="submit" value="Search" /> }
public ActionResult FiltredPrice(Decimal? fromPrice, Decimal? toPrice) { if (!fromPrice.HasValue) fromPrice = Decimal.Zero; if (!toPrice.HasValue) toPrice = fromPrice.GetValueOrDefault(Decimal.Zero+1); if (toPrice < fromPrice) toPrice = fromPrice.GetValueOrDefault(Decimal.Zero + 1); ViewBag.fromDate = fromPrice; ViewBag.toDate = toPrice; var voitures = db.Voitures .Where(c => c.Price >= fromPrice && c.Price < toPrice) .ToList(); return View(voitures); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)