【发布时间】:2015-10-23 14:25:59
【问题描述】:
我在视图中有以下按钮
<button id="Export" class="btn btn-default custom" type="button">
<i class="glyphicon glyphicon-file"></i>Export to Excel
</button>
我希望它导出我在ViewData 中的材料列表
我已经有逻辑了。代码可以在ActionResult 或普通方法中,它会是这样的:
[HttpPost]
public void Export(List<int> listPassed)
{
//stuff here
}
我尝试添加href="@Url.Action("Export", "Materials", new { export_documentation = true })",但没有成功。
我可以通过覆盖ActionLink 方法来做到这一点,但我会丢失字形图标。我想避免的事情。
ActionLink 的覆盖也没有成功。
我尝试过 Ajax,但我现在不擅长 jscript 和 ajax 以及所有这些东西。
编辑
@using (Html.BeginForm("Export", "Materials",
FormMethod.Post, new { listPassed = Request["SelectList"] }))
{
<button id="Export" class="btn btn-default custom" type="submit">
<i class="glyphicon glyphicon-file"></i>Export to Excel
</button>
}
这行不通。
那么,怎样才能给方法发送参数呢?
【问题讨论】:
-
使用表单提交值。使用 ViewData 参数对表单值进行编码。
-
我如何从视图中请求这个变量
ViewData["SelectList"] = HttpContext.Session["SelectList"] ?? new List<int>();?
标签: html ajax asp.net-mvc html-helper