View 1 - Just to enter parameters
<p> Enter Year: @Html.TextBox("Year")</p>
<p> Enter Quarter: @Html.TextBox("Qtr")</p>
<p> Enter Division: @Html.TextBox("Div")</p>
<p><input id="Submit" type="button" value="button" /></p>
Controller for View 2
namespace BSIntranet.Controllers
{
public class DivisionIncomeController : Controller
{
private ProjectionsEntities db = new ProjectionsEntities();
// GET: DivisionIncome
public ActionResult Index()
{
return View(db.JobRecaps.ToList());
}
}
}
I don't know what or how to get started here. Thanks for your help!!
EDIT using System; using System.Collections.Generic;
public partial class JobRecap
{
public int ID { get; set; }
public string Job_ID { get; set; }
public int Year { get; set; }
public int Qtr { get; set; }
public string Div { get; set; }
public string PreparedBy { get; set; }
public string ReviewedBy { get; set; }
public Nullable<System.DateTime> Date { get; set; }
public Nullable<System.DateTime> ProjStart { get; set; }
public Nullable<System.DateTime> ProjComp { get; set; }
public string SvgsSplit { get; set; }
public Nullable<int> OwnerSplit { get; set; }
public Nullable<int> BSSplit { get; set; }
public string JointVent { get; set; }
public Nullable<int> BSPct { get; set; }
public string ContractType { get; set; }
public string ContractWritten { get; set; }
public Nullable<decimal> CurContrAmt { get; set; }
public string FeeBasis { get; set; }
public Nullable<decimal> EstTotFeePct { get; set; }
public Nullable<decimal> EstTotFeeAmt { get; set; }
public string PreconFeeBasis { get; set; }
}
To keep things simple you can simply add int? Year, int? Qtr, string Div
parameters to your Index
action and search using them:
public ActionResult Index(int? Year, int? Qtr, string Div)
{
var data= db.JobRecaps.AsQueryable();
if(Year.HasValue)
data= data.Where(x=>x.Year == Year);
if(Qtr.HasValue)
data= data.Where(x=>x.Qtr == Qtr );
if(!string.IsNullOrEmpty(Div))
data= data.Where(x=>x.Div == Div );
return View(data.ToList());
}
Note:
Also you can separate concerns and create a JobRecapSearchModel
containing those search parameters and use it as parameter of action and also create a JobRecapBusinessLogic
class containing a List<JobRecap> Search(JobRecapSearchModel searchMode)
method with the business that I used above. This way you will have a more flexible and beautiful controller.
To learn more about how to use such method and the benefits you can take a look at this question:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With