I have a confusing issue with passing parameters from a view to controller in MVC 4. The problem is that I have created a view and I have created the following code :
<% using (Html.BeginForm("DisplaySummaryFigures", "Report", FormMethod.Post, new { Par1 = "some", Par2 = "some" }))
{ %>
<%: Html.ValidationSummary(true)%>
<table id="tblInsertDates">
<tr>
<th>
<asp:Label ID="Label1" runat="server" Text="lblStratDate"> Insert the Start Date:</asp:Label>
<input type="date" name="TxtStartDate" value="" />
</th>
<th>
<asp:Label ID="Label2" runat="server" Text="lblEndDate" Style="padding-left: 5px">Insert the End Date:</asp:Label>
<input type="date" name="TxtEndDate" value="" /><br />
</th>
</tr>
<tr>
<td>
<input type="submit" name="SubmitDates" value="Enter" /><br />
</td>
</tr>
</table>
inside my controller, I have passed them as the following:
[HttpGet]
public ActionResult ExportSummaryFiguresToCSV()
[HttpPost]
public ActionResult ExportSummaryFiguresToCSV(DateTime TxtStartDate, DateTime TxtEndDate)
{
StringWriter sw = new StringWriter();
DateTime dtStartDateFromUser = TxtStartDate;
DateTime dtEndDateFromUser = TxtEndDate;
when I run the program is returns the following Error :( :
The parameters dictionary contains a null entry for parameter 'TxtStartDate' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult TotalSharepointDetails(System.DateTime, System.DateTime)' in 'SalesStaticsWebSite.Controllers.ReportController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parametersere
Any ideas please ?? Thanks in Advance