【发布时间】:2017-07-27 05:18:33
【问题描述】:
我的视图中有一个表单:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.DateFrom, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DateFrom, new { htmlAttributes = new { @class = "form-control date-picker" } })
@Html.ValidationMessageFor(model => model.DateFrom, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DateTo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DateTo, new { htmlAttributes = new { @class = "form-control date-picker" } })
@Html.ValidationMessageFor(model => model.DateTo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" formAction=@Url.Action("CreateReport") />
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EMail, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EMail, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EMail, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Send to email" class="btn btn-default" formAction=@Url.Action("SendEmail") />
</div>
</div>
</div>
}
如您所见,我有两个按钮,第一个按钮调用 CreateReport 操作,然后发送按钮调用 SendEmail 操作。我想创建报告,然后通过电子邮件发送此报告。
这是我的控制器操作:
public ActionResult Index()
{
Report
report=ReportRepository.GetReport(DateTime.Parse("02.08.1996"), DateTime.Parse("07.08.1996"));
return View(report);
}
public ActionResult CreateReport(Report report)
{
report = ReportRepository.GetReport(report);
return View("Index", report);
}
public ActionResult SendEmail(Report report)
{
return View("Index", report);
}
还有我的模型课:
public class Report
{
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<OrderDetails> Orders { get; set; }
[Display(Name = "Email address")]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string EMail { get; set; }
}
所以我的意思是我在 CreateReport 操作中填写订单列表并显示它,然后按“发送到电子邮件”按钮,这就是所谓的“SendEmail”操作,我将订单列表保存到文件并发送。
问题是在“SendEmail”操作中列表为空。 我该如何解决?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-5 submit-button