-1

A new blank browserwindow opens on click of the below link created by statement below

@Html.ActionLink(item.InvoiceNumber, "SendPdfStatement", "Invoice", new { item.InvoiceNumber }, new { target = "_blank" })

I have tried with

@Html.ActionLink(item.InvoiceNumber, "SendPdfStatement", "Invoice", new { item.InvoiceNumber }, new { target = "_self" }) which makes original window blank

@Html.ActionLink(item.InvoiceNumber, "SendPdfStatement", "Invoice", new { item.InvoiceNumber }, null) this also makes original window blank

@Html.ActionLink(item.InvoiceNumber, "SendPdfStatement", "Invoice", new { item.InvoiceNumber } raises exception in invoked method as tem.InvoiceNumber is taken as the html parameter

Please suggest

public void SendPdfStatement(string InvoiceNumber)

{

        InvoiceNumber = InvoiceNumber.Trim();

        ObjectParameter[] parameters = new ObjectParameter[1];
        parameters[0] = new ObjectParameter("InvoiceNumber", InvoiceNumber);

        List<Models.Statement> list = new List<Models.Statement>();
        list = _db.ExecuteFunction<Models.Statement>("uspInvoiceStatement", parameters).ToList<Models.Statement>();

        var statementResult = _db.ExecuteFunction<Models.Statement>("uspInvoiceStatement", parameters);
        Models.Statement statement = statementResult.SingleOrDefault();

        pdfStatementController.WriteInTemplate(statement);

    }
tereško
  • 58,060
  • 25
  • 98
  • 150
14578446
  • 1,044
  • 7
  • 30
  • 50
  • Can you clarify you question? Are you asking why is the new window blank? – Ashok Padmanabhan Dec 13 '11 at 20:28
  • does your SendPdfStatement action on the Invoice Controller return anything? – Patricia Dec 13 '11 at 20:31
  • you just asked this question here http://stackoverflow.com/questions/8495404/new-window-opens-on-click-of-actionlink/8495638#8495638 – bobek Dec 13 '11 at 20:36
  • my method does not return anything. I simply want to invoke a method without opening a new window and also my original window(with the link) should remain as it is – 14578446 Dec 13 '11 at 20:36
  • You need an Ajax function then. The page will not reload and your function will be executed, but you still need to return the View. – bobek Dec 13 '11 at 20:47
  • can you tell me the ajax function which can be used here? – 14578446 Dec 13 '11 at 20:53

1 Answers1

0

You're getting a blank window because your controllers signature is

public void SendPdfStatement(string InvoiceNumber) { .. } - which practically returns a void to your view.

If you do want to return something, turn your controller into public ActionResult SendPdfStatement(...) or even just string.. whatever you want to return.

If you do not want to return anything use @Ajax.Actionlink to call that method instead.

Ron Sijm
  • 8,490
  • 2
  • 31
  • 48