Home > Enterprise >  How do i pass multiple parameters to c# method from browser URL
How do i pass multiple parameters to c# method from browser URL

Time:11-24

I ad trying to pass parameters to call the following C# method

public ActionResult GenerateInvoicePDFByInvoiceNum(string id,string apikey)
{
    IInvoiceRepository rep = db.GetInvoiceRepository();
    //
    var api = Guid.Parse(apikey);
    Invoice invoice = rep.GetByExpression(i => i.InvoiceNo.Equals(id) && i.Visit.Branch.Practice.APIKey.ToString().Equals(apikey)).FirstOrDefault();
    if (invoice==null)
    {
        return HttpNotFound();
    }

    //return new Rotativa.ActionAsPdf("PrintInvoice", new { id = invoice.Id })
    //{
    //    //CustomSwitches = "--load-error-handling ignore "
    //    CustomSwitches = "--disable-javascript"
    //};

    return RedirectToAction("GenerateInvoicePDF", new { id = invoice.Hash });

}

From the browser I am trying to call it with a call like this which worked when I had only one parameter, but I don't know how to change those to pass the second parameter

http://foobar.n.co.za/Newlook/PrintInvoice/GenerateInvoicePDFByInvoiceNum/72341d

Thanks

CodePudding user response:

On your url: http://foobar.n.co.za/Newlook/PrintInvoice/GenerateInvoicePDFByInvoiceNum/72341d

"/72341d" represents an optional parameter.

Try to pass a query string. To do that, you need to specify the parameter name and value you want to pass.

http://foobar.n.co.za/Newlook/PrintInvoice/GenerateInvoicePDFByInvoiceNum?id=72341d&apikey=YOUR_API_KEY

CodePudding user response:

This is how you pass parameters by url:

http://foobar.n.co.za/Newlook/PrintInvoice/GenerateInvoicePDFByInvoiceNum?id=72341d&apikey=yourapikeygoeshere

CodePudding user response:

You can pass multiple parameters as "?param1=value1&param2=value2"

http://foobar.n.co.za/Newlook/PrintInvoice/GenerateInvoicePDFByInvoiceNum?id=1&1pikey=2
  • Related