在 MVC 4 中将参数从视图传递到控制器时,我遇到了一个令人困惑的问题。问题是我创建了一个视图并且创建了以下代码:
<% 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>
在我的控制器内部,我将它们传递如下:
[HttpGet]
public ActionResult ExportSummaryFiguresToCSV()
[HttpPost]
public ActionResult ExportSummaryFiguresToCSV(DateTime TxtStartDate, DateTime TxtEndDate)
{
StringWriter sw = new StringWriter();
DateTime dtStartDateFromUser = TxtStartDate;
DateTime dtEndDateFromUser = TxtEndDate;
当我运行程序时返回以下错误:(:
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.
参数名称:parametersere
请问有什么想法吗??提前致谢