Reputation: 3980
I have an mvc controller function as a get and I wish to also pass a Device id to certain gets, the device id is a guid which attaches itself to the users mobile.
I know that in a put I can pass a class but using http get and httpclient how does one pass multiple parameters it's too late to switch to asp.net core at this stage of the project might for next release.
// GET: BomDetails/Details/5
[HttpGet]
public ActionResult Details(string id)
{
List<BomTransAction> result = new List<BomTransAction>();
try
{
bool doesExit = database.DoesBomTransactionExist(id);
result = database.GetBomData(id, false);
if (doesExit)
{
result = database.GetBomsTransactionListForDevice(id);
}
{
result = database.GetBomData(id, true);
}
}catch(Exception ex)
{
logger.Warn("Exception on details of BomDetailsController " + ex.ToString());
}
return Json(result, JsonRequestBehavior.AllowGet);
}
Its the second function i need to pass the parameter to this will be only used some times so I don't know how to modify my route config to allow for this.
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Upvotes: 0
Views: 6413
Reputation: 3817
The only thing you need is to add another parameter in your action method:
[HttpGet]
public ActionResult Details(string id, string anotherParameter)
The action can be called using this URL: BomDetails/Details?id=1&anotherParameter=testValue
Upvotes: 1