How to put a link in jquery table that opens a pdf using generic handler?

1

good morning: I have the following code:

generic handler

public void ProcessRequest(HttpContext context)
{
  string nombreArchivo,tipo;
 //   int id = 12725; NOTA:"Si hago asi no marca error y si me muestra el pdf"
    int id = int.Parse(context.Request.QueryString["Id"]);

     using (SqlConnection con = new SqlConnection(myconsql))
    { 
        using (SqlCommand cmd = new SqlCommand())
        {   
            cmd.CommandText = "SELECT nomb, ruta, tipo FROM Cat WHERE id=@Id";
            cmd.Parameters.AddWithValue("@Id", id);
            cmd.Connection = con; 
            con.Open(); 
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {   
                sdr.Read();
                ruta = (byte[])sdr["ruta"];
                tipo = sdr["tipo"].ToString();
                nombArchivo = sdr["nombArchivo"].ToString();
            } 
            con.Close();
        } 
    } 
    context.Response.Buffer = true;
    context.Response.Charset = "";
    if (context.Request.QueryString["download"] == "1")
    {
        context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + nombArchivo);
    }    
    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    context.Response.ContentType = "application/pdf";
    context.Response.BinaryWrite(ruta);
    context.Response.Flush(); 
    context.Response.End();

}
public bool IsReusable
{
    get
    {

        return false;
    }

mark this error:

  

Value can not be null.   Parameter name: String Line 23:
  int id = int.Parse (context.Request.QueryString ["Id"]);

So I have it in source asp.net c #:

table.append("<tr id='row_" + i + "'><td name='id'>" + Data[i].id + "</td> +  " 
"<td style='display: none'>" + Data[i].ruta + "</td>" + " <td style='display: none'>" + Data[i].tipo + "</td>" + "<td name='nombArchivo'>" + "   <a href='http://localhost:25429/FileCS.ashx?Id='" + Data[i].id +  "target='_blank='_blank'>" + Data[i].nombArchivo + "</a></td></td></tr>");

and when I run it I get that error, but without changing it if I assign a specific id in generic if you show it to me, I'll be doing something wrong in the html table source ?????

    
asked by AraceLi Torres 27.06.2016 в 17:48
source

1 answer

1

Replaces:

<a href='http://localhost:25429/FileCS.ashx?Id='" + Data[i].id +  "target='_blank='_blank'>" 

By:

<a href='http://localhost:25429/FileCS.ashx?id='" + Data[i].id +  " target='_blank'>" 

Before the target there must be a blank space to work as expected, plus there is another "_blank" extra.

    
answered by 27.06.2016 в 19:22