0
右鍵,感覺就像一個很小白的問題,但還是新的這一切:)日期選擇器來傳遞參數MVC5
我在圖書館一類是應該基於幾個變量來生成文檔應該從MVC5網絡應用程序傳遞。
我看了一些教程,但我無法理解它,所以也許我正在接近這個錯誤的方式嗎?
這是我的模型:
public class SummaryTicketsReportModel
{
public bool ServiceDesk { get; set; }
[DisplayFormat(DataFormatString = "{0:DD/MM/YYYY", ApplyFormatInEditMode = true)]
[DataType(DataType.Date)]
[DisplayName("From")]
public DateTime StartDate { get; set; }
[DisplayFormat(DataFormatString = "{0:DD/MM/YYYY", ApplyFormatInEditMode = true)]
[DataType(DataType.Date)]
[DisplayName("From")]
public DateTime EndDate { get; set; }
//Do I need this?
//public SummaryTicketsReportModel()
//{
// StartDate = new DateTime();
// EndDate = new DateTime();
//}
這是我的控制器:
public class SummaryReportController : Controller
{
// GET: SummaryReport
public ActionResult Index()
{
return View();
}
//POST Action
[HttpPost]
public ActionResult Index(SummaryTicketsReportModel serviceDesk, SummaryTicketsReportModel startDate, SummaryTicketsReportModel endDate)
{
// takes in the view model
var selectedServiceDesk = serviceDesk;
var selectedStartDate = startDate;
var selectedEndDate = endDate;
var generateReport = new TicketSummaryReport();
//Needs to access the following: MonthSummaryReport (ServiceDesk, StartDate, EndDate, summaryDocX)
//return generateReport.MonthsSummaryReport();
}
}
這是我的看法:
@using System.Drawing
@model SummaryTicketsReportModel
@{
ViewBag.Title = "TicketsSummaryReport";
}
<h2>TicketsSummaryReport</h2>
@using (Html.BeginForm())
{
<tr>
<td>
@Html.TextBox("", String.Format("{0:d}", Model.StartDate))
</td>
<td>
@Html.TextBox("", String.Format("{0:d}", Model.EndDate))
</td>
<td style="text-align: center">
@Html.CheckBoxFor(model => model.ServiceDesk)
</td>
</tr>
<input type="submit"/>
}
你的問題是什麼? – 2014-10-29 11:01:23
它有點拒絕工作:(因爲「不是所有的代碼都返回值」,所以沒有運行) – 2014-10-29 11:04:46
看起來你沒有從你的控制器動作返回任何東西,你註釋掉的方法返回什麼?如果它是'SummaryTicketsReportModel '你很可能想要類似'return View(generateReport.MonthsSummaryReport());' – 2014-10-29 11:07:05