Reputation: 887
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
Upvotes: 0
Views: 931
Reputation: 173
You have three choices to do this:
Pass parameters using query string like /?id=value&apikey=value
Add a custom route in "RouteConfig" (~/App_Start/RouteConfig.cs) like below:
routes.MapRoute(
name: "RouteName",
url: "{controller}/{action}/{id}/{apikey}"
);
Use attribute routing. To do this first enable it by calling the "routes.MapMvcAttributeRoutes()" method in "RouteConfig" and then apply the [Route(urlPttern)] attribute to the related action and pass the url pattern to the method
after applying solution 2 or 3 you can pass parameters in url like:
"/foobar.n.co.za/Newlook/PrintInvoice/GenerateInvoicePDFByInvoiceNum/72341d/apikeyvalue"
Upvotes: 0
Reputation: 3495
You can pass multiple parameters as "?param1=value1¶m2=value2"
http://foobar.n.co.za/Newlook/PrintInvoice/GenerateInvoicePDFByInvoiceNum?id=1&1pikey=2
Upvotes: 1
Reputation: 199
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.
Upvotes: 1