小编roh*_*ngh的帖子

如何通过asp.net MVC 4中的ajax请求下载文件

以下是我的代码:

ActionResult DownloadAttachment(student st)
{          
    var file = db.EmailAttachmentReceived.FirstOrDefault(x => x.LisaId == st.Lisaid);

    byte[] fileBytes = System.IO.File.ReadAllBytes(file.Filepath);
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, file.Filename);                 
}
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的脚本

$(function () {
    $("#DownloadAttachment").click(function () {
        $.ajax({
            url: '@Url.Action("DownloadAttachment", "PostDetail")',
            contentType: 'application/json; charset=utf-8',
            datatype: 'json',
            type: "GET",
            success: function () {
                alert("sucess");
            }
        });    
    });
});      
Run Code Online (Sandbox Code Playgroud)

如何返回文件下载追求上面的代码?

jquery json asp.net-ajax asp.net-mvc-4

11
推荐指数
2
解决办法
6万
查看次数

在完成报表查看器的加载之前,ReportViewer会阻止其他功能

这是ReportViewer控件:

  <form id="reportForm" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="360000">
    </asp:ScriptManager>
    <div>
      <rsweb:ReportViewer ID="mainReportViewer" runat="server" Width="100%" 
            Height="100%" SizeToReportContent="True"  >
      </rsweb:ReportViewer>
    </div>
  </form>
Run Code Online (Sandbox Code Playgroud)

这是页面背后的代码:

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["UserInfo"] == null)
    {
        Response.Redirect("~/account/login", true);
    }
    string ReportPath = "";
    try
    {
        if (mainReportViewer.Page.IsPostBack) return;

        mainReportViewer.ProcessingMode = ProcessingMode.Remote;

        mainReportViewer.ServerReport.ReportServerUrl = new Uri(
            @"" + ConfigurationManager.AppSettings["ReportServer"].ToString()
        );
        ReportPath = Convert.ToString(ConfigurationManager.AppSettings["ReportPath"]);
        if (!string.IsNullOrEmpty(ReportPath))
        {
            if (ReportPath.Substring(0, 1) == "/")
            {
                ReportPath = ReportPath.Substring(1, ReportPath.Length - 1);
            }
            if (ReportPath.Substring(ReportPath.Length - 1, 1) …
Run Code Online (Sandbox Code Playgroud)

.net asp.net asp.net-mvc reportviewer

7
推荐指数
1
解决办法
1187
查看次数

如何在c#中动态更改td的colspan?

  <FooterTemplate>
    <tr style="background-color:Orange;">
    < td width="6%" align="center" id = "tdFooter" runat = "server" colspan = "3">                                   
    </td>
</tr>
</FooterTemplate>
Run Code Online (Sandbox Code Playgroud)

我有一个转发器控件,我有这个页脚模板.我想要的是在一些if子句的基础上更改itemdatabound事件(c#)的tdFooter的colspan.我怎么能这样做?

if (e.Item.ItemType == ListItemType.Footer)
{
    if(role = 0)
       {
         //tdfooter colspan should be 3
       }
else
      {
        //tdfoote colspan should be 2
      }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net repeater

3
推荐指数
1
解决办法
6217
查看次数

理解using语句

我写了两个代码:

代码块1:

Stream dataStream;
using (var response = (HttpWebResponse)req.GetResponse())
{
    dataStream = response.GetResponseStream();
}

//Open the stream using a StreamReader for easy access
using (var reader = new StreamReader(dataStream))
{
    data = reader.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)

代码块2:

Stream dataStream;
using (var response = (HttpWebResponse)req.GetResponse())
{
    dataStream = response.GetResponseStream();

    //Open the stream using a StreamReader for easy access
    using (var reader = new StreamReader(dataStream))
    {
        data = reader.ReadToEnd();
    }
}
Run Code Online (Sandbox Code Playgroud)

代码块1抛出错误:stream is not reachable.
虽然在进步中我认为两个代码将工作相同.
我在代码块2中添加了使用块到整个语句,它正在工作.
但我很困惑,为什么它会在代码块1中抛出错误

.net c# using-statement

1
推荐指数
1
解决办法
263
查看次数

如何在 C# 中的 Xelement 内使用 foreach 循环

 XElement doc = null;
 doc = new XElement("root");
 foreach (var content in emailContents)
                                    {
    doc.Add(new XElement("Email",
            new XElement("FromAddress", content.FromAddress),
            new XElement("EmailReceivedOn", content.receivedOnemail),
            new XElement("Subject", content.subject),
            new XElement("Body", content.body)));
    // I want to add the below code after the body element is created in the xml inside the email element section; How to do the same?
     foreach (var attachment in content.attachments)
        {
          doc.Add(new XElement("attachmentname"), attachment.Filename),
          doc.Add(new XElement(("attachmentpath"), attachment.Filepath)        
        }
}
Run Code Online (Sandbox Code Playgroud)

基本上 content.attachment 是附件名称的列表,我想在 body 元素后面添加该列表。如何做同样的事情?

c# xml xelement

0
推荐指数
1
解决办法
8713
查看次数

varchar(max)在变量中设置时截断字符串

我正在尝试打印动态查询,但正在发生的是打印查询时字符被截断.

declare @sql varchar(max)
set @sql = cast('select*from.................length is huge' as varchar(max))
print @sql
Run Code Online (Sandbox Code Playgroud)

知道怎么解决吗?

sql sql-server varchar truncate

0
推荐指数
1
解决办法
897
查看次数