我查看了所有相关问题,但仍然不确定。我是菜鸟,还在学习。
我有这样的看法:
<% using (Html.BeginForm("TradeUKKPISearchesDataExtract", "Report")) //action/controller
{ %>
<div style="padding: 10px; background-color: #eeeeee; width: 250px; border: 1px solid #cccccc;">
<div style="float: left; width: 100px; padding-top: 3px;">
<p style="color:Red"><%: Html.DropDownList("Choose a Sunday: ", ((DateTime[])ViewData["Sundays"]).Select(day => new SelectListItem() { Text = day.ToString(), Value = day.ToString() }), "--Select--")%>
</p>
</div>
<div class="clear"></div>
</div>
<div style="text-align:right; width: 272px; padding-top: 30px;">
<input type="submit" id="search-submit" value="Search" />
</div>
当我点击提交按钮时,我在哪里设置需要返回的值?
在 html.BeginForm 或 Html.DropDownList 中?
我的行动:
[HttpPost]
public ActionResult TradeUKKPISearchesDataExtract(DateTime date)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Title, Total");
var reportData = _reportingService.GetTradeUKKPISearches(date);
foreach (var item in reportData)
{
sb.AppendLine(String.Concat("\"", item.Key, "\", ", item.Value));
}
byte[] textBytes = Encoding.UTF8.GetBytes(sb.ToString());
return File(textBytes, "application/csv", "TradeUKKPISearchesDataExport.csv");
}
谢谢