If you are using RazorWebPages then you just need to add method attribute to your form tage like
<form method="post" class="form-horizontal">
then your following code will work properly
@{
Report.GenerateReport(Request["ProjectName"], "from date here","to date here");
}
but there will be need to convert your FromMonth and FromYear field to DateTime and check the project name is exist other wise Report.GenerateReport function throw Exception, so for that you can write that as
@{
var porjectName = Request["ProjectName"];
if (!string.IsNullOrEmpty(porjectName ))
{
var fromDate = DateTime.Parse(string.Format("{0}-{1}-{2}", Request["FromYear"], Request["FromMonth"], 1));
var toDate = DateTime.Parse(string.Format("{0}-{1}-{2}", Request["ToYear"], Request["ToMonth"], 1));
Report.GenerateReport(porjectName, fromDate, toDate);
}
}
You can find more information about asp.net razor webpage @ http://www.asp.net/web-pages/overview/getting-started/introducing-aspnet-web-pages-2/form-basics
Or if you are using Asp.net Mvc then you will need to write Get/Post Actions. In the Get Action your initial view will be rendered and by Submit button you will hit the Post Action where the best way will be load the values in a wrapper class called Model/ViewModel and then pass that model to your Report.GenerateReport method.
Controller Class:
public class ReportGeneratorController : Controller
{
[HttpGet]
public ActionResult ProjectReport()
{
return View();
}
[HttpPost]
public ActionResult ProjectReport(ReportParamModel model)
{
return View(model);
}
}
Your Model
public class ReportParamViewModel
{
public string ProjectName {get;set;}
public int FromMonth {get;set;}
public int FromYear {get;set;}
public int ToMonth {get;set;}
public int ToYear {get;set;}
public DateTime GetFromDate()
{
return new DateTime(FromYear, FromMonth, 1);
}
public DateTime GetToDate()
{
return new DateTime(ToYear, ToMonth, 1);
}
}
Your view or cshtml File
@Model ReportParamViewModel
<!-- your current html -->
@{
Report.GenerateReport(model.ProjectName, model.GetFromDate(),model.GetToDate());
}
You can find more information about Asp.net Mvc @ http://www.asp.net/mvc/overview/getting-started