html输入参数,传递输入参数,通过Html.ActionLink

控制器的方法当用户点击Html.ActionLink,我需要调用一个控制器的方法,将下载该用户的csv报告。我还需要将这个控制器的值从两个输入框中传递出来,它们表示他们正在查找的开始日期和结束日期范围。传递输入参数,通过Html.ActionLink

目前我可以指定使用jQuery的Html.ActionLink参数,但是他们没有把它回控制器。控制器方法中的两个参数都使用null值进行实例化。

我也不能使用表单/提交方式为已经被这种特殊的形式来让用户看到导出到CSV之前要求在日期范围内的数据。

的jQuery

$(document).ready(function() {

$('#startDate').change(function() {

$('a').attr('start', $(this).val());

});

$('#endDate').change(function() {

$('a').attr('end', $(this).val());

});

});

ASP MVC 3查看

@using (Html.BeginForm())

{

@Html.ActionLink("Export to Spreadsheet", "ExportToCsv", new { start = "" , end = ""})

@ViewBag.ErrorMessage

}

控制器方法

public void ExportToCsv(string start, string end)

{

var grid = new System.Web.UI.WebControls.GridView();

var banks = (from b in db.AgentTransmission

where b.RecordStatus.Equals("C") &&

b.WelcomeLetter

select b)

.AsEnumerable()

.Select(x => new

{

LastName = x.LastName,

FirstName = x.FirstName,

MiddleInitial = x.MiddleInitial,

EffectiveDate = x.EffectiveDate,

Status = x.displayStatus,

Email = x.Email,

Address1 = x.LocationStreet1,

Address2 = x.LocationStreet2,

City = x.LocationCity,

State = x.LocationState,

Zip = "'" + x.LocationZip,

CreatedOn = x.CreatedDate

});

grid.DataSource = banks.ToList();

grid.DataBind();

string style = @" ";

Response.ClearContent();

Response.AddHeader("content-disposition", "attachment; filename=WelcomeLetterOutput.xls");

Response.ContentType = "application/excel";

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

grid.RenderControl(htw);

Response.Write(style);

Response.Write(sw.ToString());

Response.End();

}

2013-08-06

NealR

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值