Currently I have a page that looks like this.
and I have an action link on my home page that looks like this
<li>@Html.ActionLink("Off Site Inventory Order (OSI)", "Index", "SalesOrders", new { type = "OSI"}, null) </li>
That link however does not do what I want it to do so I was hoping to get some help. When I click that click on the home page I want it to direct me to that page I showed you above however I want it to be filtered by the order type of 'OSI' so that it automatically looks like this
[
where it filters the page to OSI orders instead.
Here is my salesOrderController GET method
public ActionResult Index(int? wholesalerID)
{
int perpage = 50;
ViewBag.ErrorMessage = "";
if (TempData["ErrorMessage"] != null)
ViewBag.ErrorMessage = TempData["ErrorMessage"];
var salesOrders = db.SalesOrders
.Include(s => s.Customers)
.Include(s => s.Partners)
.Include(s => s.Wholesaler)
.Include(s => s.RnD)
.Include(s => s.ECommerce)
.Include(s => s.Direct)
.Include(s => s.Marketing)
.Where(x => x.deleted.Equals(false))
.OrderBy(x => x.SalesOrderStatus).ThenByDescending(x => x.ID);
ViewBag.CanSeeCost = false;
if (IGT.canAccess(IGT.userId, AccessRestrictions.ModifySalesOrder, false))
{
ViewBag.CanSeeCost = true;
var total = salesOrders.Where(s => ((s.SalesOrderStatus == SOStatus.Released) || (s.SalesOrderStatus == SOStatus.Shipped) || s.SalesOrderStatus == SOStatus.Close) && !s.deleted);
ViewBag.TotalRetail = total.Sum(x => x.totalRetail);
ViewBag.TotalShipping = total.Sum(x => x.totalShipped);
ViewBag.TotalRemaining = ViewBag.TotalRetail - ViewBag.TotalShipping;
if (total.FirstOrDefault(x => x.NoCharge) != null)
{
ViewBag.TotalRetailNoCharge = total.Where(x => x.NoCharge).Sum(x => x.totalRetail);
ViewBag.TotalShippingNoCharge = total.Where(x => x.NoCharge).Sum(x => x.totalShipped);
ViewBag.TotalRemainingNoCharge = ViewBag.TotalRetailNoCharge - ViewBag.TotalShippingNoCharge;
}
else
{
ViewBag.TotalRetailNoCharge = 0;
ViewBag.TotalShippingNoCharge = 0;
ViewBag.TotalRemainingNoCharge = 0;
}
}
ViewBag.Customers = new SelectList(db.SalesOrders.Where(x => x.customerID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.customerID, x.CustomerName }).Distinct(), "customerID", "CustomerName");
ViewBag.Retailers = new SelectList(db.SalesOrders.Where(x => x.partnerID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.partnerID, x.CustomerName }).Distinct(), "partnerID", "CustomerName");
ViewBag.Dealers = new SelectList(db.SalesOrders.Where(x => x.wholesalerID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.wholesalerID, x.CustomerName }).Distinct(), "wholesalerID", "CustomerName");
ViewBag.RnDs = new SelectList(db.SalesOrders.Where(x => x.rndID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.rndID, x.CustomerName }).Distinct(), "rndID", "CustomerName");
ViewBag.ECommerces = new SelectList(db.SalesOrders.Where(x => x.eID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.eID, x.CustomerName }).Distinct(), "eID", "CustomerName");
ViewBag.Directs = new SelectList(db.SalesOrders.Where(x => x.directID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.directID, x.CustomerName }).Distinct(), "directID", "CustomerName");
ViewBag.Marketings = new SelectList(db.SalesOrders.Where(x => x.marketingID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.marketingID, x.CustomerName }).Distinct(), "marketingID", "CustomerName");
ViewBag.PO = new SelectList(db.SalesOrders.Where(x => !x.deleted).Where(x => x.CustomerPONumber != null), "CustomerPONumber", "CustomerPONumber");
ViewBag.orderby = "true";
ViewBag.sortOrder = "status";
ViewBag.wholesalerID = wholesalerID;
ViewBag.page = 1;
ViewBag.totalPages = (int)Math.Ceiling((float)salesOrders.Count() / perpage);
return View(salesOrders.Take(perpage).ToList());
}
But not sure of how to do the post, I have a filter method that works for all the filters on the screen but not sure if I just manipulate that, or create a index post method or what
In response to the answer I received, I made it resemble my filter method so now it looks like this
if (type == "OSI")
{
ordertype = 3; // OSI Order Id
ViewBag.Customers = new SelectList(db.SalesOrders.Where(x => x.customerID != null && !x.deleted && x.OrderType == (SOType)ordertype).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.customerID, x.CustomerName }).Distinct(), "customerID", "CustomerName");
ViewBag.Retailers = new SelectList(db.SalesOrders.Where(x => x.partnerID != null && !x.deleted && x.OrderType == (SOType)ordertype).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.partnerID, x.CustomerName }).Distinct(), "partnerID", "CustomerName");
ViewBag.Dealers = new SelectList(db.SalesOrders.Where(x => x.wholesalerID != null && !x.deleted && x.OrderType == (SOType)ordertype).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.wholesalerID, x.CustomerName }).Distinct(), "wholesalerID", "CustomerName");
ViewBag.RnDs = new SelectList(db.SalesOrders.Where(x => x.rndID != null && !x.deleted && x.OrderType == (SOType)ordertype).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.rndID, x.CustomerName }).Distinct(), "rndID", "CustomerName");
ViewBag.ECommerces = new SelectList(db.SalesOrders.Where(x => x.eID != null && !x.deleted && x.OrderType == (SOType)ordertype).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.eID, x.CustomerName }).Distinct(), "eID", "CustomerName");
ViewBag.Directs = new SelectList(db.SalesOrders.Where(x => x.directID != null && !x.deleted && x.OrderType == (SOType)ordertype).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.directID, x.CustomerName }).Distinct(), "directID", "CustomerName");
ViewBag.Marketings = new SelectList(db.SalesOrders.Where(x => x.marketingID != null && !x.deleted && x.OrderType == (SOType)ordertype).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.marketingID, x.CustomerName }).Distinct(), "marketingID", "CustomerName");
}
else
{
ViewBag.Customers = new SelectList(db.SalesOrders.Where(x => x.customerID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.customerID, x.CustomerName }).Distinct(), "customerID", "CustomerName");
ViewBag.Retailers = new SelectList(db.SalesOrders.Where(x => x.partnerID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.partnerID, x.CustomerName }).Distinct(), "partnerID", "CustomerName");
ViewBag.Dealers = new SelectList(db.SalesOrders.Where(x => x.wholesalerID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.wholesalerID, x.CustomerName }).Distinct(), "wholesalerID", "CustomerName");
ViewBag.RnDs = new SelectList(db.SalesOrders.Where(x => x.rndID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.rndID, x.CustomerName }).Distinct(), "rndID", "CustomerName");
ViewBag.ECommerces = new SelectList(db.SalesOrders.Where(x => x.eID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.eID, x.CustomerName }).Distinct(), "eID", "CustomerName");
ViewBag.Directs = new SelectList(db.SalesOrders.Where(x => x.directID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.directID, x.CustomerName }).Distinct(), "directID", "CustomerName");
ViewBag.Marketings = new SelectList(db.SalesOrders.Where(x => x.marketingID != null && !x.deleted).ToList().OrderBy(x => x.CustomerName).Select(x => new { x.marketingID, x.CustomerName }).Distinct(), "marketingID", "CustomerName");
ViewBag.PO = new SelectList(db.SalesOrders.Where(x => !x.deleted).Where(x => x.CustomerPONumber != null), "CustomerPONumber", "CustomerPONumber");
}
ViewBag.orderby = "true";
ViewBag.sortOrder = "status";
ViewBag.wholesalerID = wholesalerID;
ViewBag.type = type;
ViewBag.page = 1;
ViewBag.totalPages = (int)Math.Ceiling((float)salesOrders.Count() / perpage);
return View(salesOrders.Take(perpage).ToList());
}