0
A
回答
0
我会什么,我认为你把裂缝是后,这是具有形状+结果在同一页上。我最近遇到了这个问题,我需要这种模式,并且增加了两种方法(表单和表单+结果)所需的复杂性。不是GET和POST。以下是我做的:
控制器方法:
// GET: /Reports/Refund
public ActionResult Refunds()
{
var refundVM = new RefundCheckReportViewModel();
return View(refundVM);
}
// GET: /Reports/Refund
public ActionResult RefundsResult(RefundCheckReportViewModel refundVM)
{
string errorMsg;
var ready = refundVM.IsReadyToRun(out errorMsg);
if (!ready)
ModelState.AddModelError("StartDate", errorMsg);
else
refundVM.LoadReportData(); // this method on the ViewModel fetches the report data.
return View("Refunds", refundVM);
}
查看在剃刀,其持有的形式,再加上表中报告的结果:
@model MembershipCenter.ViewModels.Report.RefundCheckReportViewModel
@{
ViewBag.Title = "Refunds";
}
<div class="formStandard">
@using (Html.BeginForm("RefundsResult", "Reports", FormMethod.Get))
{
<div class="fsHeader">
<span class="reqLabel"><a class="req">*</a>required field</span>
<strong>Refund Check Report</strong>
</div>
<div class="fsBlock">
<div class="text">Date Range: <a class="req">*</a></div>
<div class="elem">
<span class="dateRangePicker">
From: @Html.TextBoxFor(model => model.StartDate, new { @class = "short datepicker" })
To: @Html.TextBoxFor(model => model.EndDate, new { @class = "short datepicker" })
@Html.ValidationMessageFor(model => model.StartDate)
</span>
</div>
</div>
<div class="fsFinalActions">
<input type="submit" value="Generate Report" />
</div>
}
</div> <!-- end .formStandard -->
@if (Model.ReportData != null)
{
if (Model.ReportData.Any()) {
<table class="colorTable" style="margin-top: 30px;" id="resultTable">
<thead>
<tr>
<th>Date</th>
<th>Member #</th>
<th>Amount</th>
<th>Check #</th>
<th>Name</th>
<th>Reason</th>
</tr>
</thead>
<tbody>
@foreach (MembershipCenter.ViewModels.Report.RefundCheckReportViewModel.RefundReportResultItem item in Model.ReportData)
{
<tr>
<td>@item.PrintedDate</td>
<td>@Html.GetMemberLink(item.MemberNumber)</td>
<td>@item.Amount</td>
<td>@item.CheckNumber</td>
<td>@item.PayeeName</td>
<td>@item.Reason</td>
</tr>
}
</tbody>
</table>
}
else {
<div><strong>There are not Refunds for the criteria above.</strong></div>
}
}
最后,仅供参考,我的视图模型:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Membership = Biz.Business.Membership;
using Printing = Biz.Business.Printing;
namespace MembershipCenter.ViewModels.Report
{
public class RefundCheckReportViewModel
{
[Required]
public DateTime? StartDate { get; set; }
[Required]
public DateTime? EndDate { get; set; }
public List<RefundReportResultItem> ReportData = null;
public RefundCheckReportViewModel()
{
}
public bool IsReadyToRun(out string errorMessage)
{
errorMessage = string.Empty;
if (!StartDate.HasValue || !EndDate.HasValue)
errorMessage = "Please enter a start and end date";
else if (StartDate.Value <= new DateTime(2012, 11, 1).Date)
errorMessage = "Please enter a date greater than 11/1/2012 for the Start Date.";
return (errorMessage.IsNullOrEmpty());
}
public void LoadReportData()
{
ReportData = new List<RefundReportResultItem>();
var refunds = Membership.Getrefunds(blah);
var checks = Printing.GetChecks(blah);
foreach (var refund in refunds)
{
var check = checks.SingleOrDefault(c => c.RequestReferenceId == refund.Request.Id);
if (check != null)
ReportData.Add(new RefundReportResultItem(refund, check));
}
}
public class RefundReportResultItem
{
public int CheckNumber { get; set; }
public decimal Amount { get; set; }
public string PayeeName { get; set; }
public string MemberNumber { get; set; }
public string Reason { get; set; }
public string PrintedDate { get; set; }
public RefundReportResultItem(Membership.Refund refund, Printing.PrintedCheck check)
{
MemberNumber = refund.MemberId;
Reason = refund.Note;
Amount = refund.Amount;
PayeeName = check.Payee;
CheckNumber = check.CheckNumber;
PrintedDate = check.QueuedToPrint.ToShortDateString();
}
}
}
}
这视图模型下RefundReportResultItem
类是人C对于报告中每个结果项目的数据都不重要。
相关问题
- 1. 进程查询并把结果放在同一页jsp
- 2. php在同一页上显示查询结果
- 3. 查询数据库并在同一页面显示结果
- 4. 尝试以显示查询结果显示在同一页
- 5. 在Cakephp的同一页返回查询结果
- 6. 结果排序从不同的表结果在一个查询
- 7. 查询结果不同于SSRS结果
- 8. mySQL查询 - 在同一个查询中再次使用结果
- 9. 在同一查询中使用查询的结果?
- 10. PHP和Toad Oracle查询结果不同
- 11. Codeigniter和Oracle查询结果不同步
- 12. BigQuery - 在同一查询的另一部分中查询子查询的结果
- 13. 分页SELECT查询结果
- 14. 同一数据库查询结果
- 15. MongoDB的:在使用同一查询结果从查询同一文档
- 16. MySQL的 - 结合单结果查询和多结果查询到一个
- 17. codeigniter分页显示所有查询结果在一个页面
- 18. 选择查询和相同的查询具有结果
- 19. 获取查询结果的金额范围内同一查询
- 20. 来自同一个查询中查询使用结果
- 21. 使用查询结果在同一个表上获得另一个结果
- 22. 在查询结果
- 23. 两页,同样的数据库查询,不同的结果
- 24. 另一个查询的查询结果
- 25. 汇总查询和结果
- 26. Rails的查询 - 和结果
- 27. SQL查询和结果
- 28. 推和结果查询
- 29. 将查询结果除以另一个查询的结果
- 30. 过滤查询结果与另一查询结果
这是一个巨大的问题,完全依赖于任何其他因素。你想不同步吗?模型如何“复杂”,以及“所有返回数据”有多少数据?从这里开始:http://www.asp.net/mvc,回来一个更具体的问题。 –
谢谢克里斯,我简化了我的问题。 – ron