- Hello, I am very new to MVC5, Razor, and EF and I have been looking for two days and still can't figure out a solution to my problem.
- What I want to do is have a view where users enter a year, the quarter, and division. On submit, I want a controller for another view to see these parameters and filter the data before the view is rendered. Currently I have 5 different division and I want to filter only one division when the view is rendered.
- I have looked at a lot of forums, websites, etc. trying to figure this out and I haven't had any luck. I would be glad to at least get pointed in the right direction. I am trying to learn this by jumping into the fire and figuring it out myself but I need help now.
- I have the whole idea down behind how MVC works, I have no problems working with the DB, and I have been successful on learning how scaffolding works and also ViewModels. I am now trying to learn how to manipulate the data within the controller and views. Any help would be appreciated.
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 yourIndex
action and search using them:Note:
Also you can separate concerns and create a
JobRecapSearchModel
containing those search parameters and use it as parameter of action and also create aJobRecapBusinessLogic
class containing aList<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: