0
I need my controller to get a parameter from a URL (localhost/Check/123456
), where 12346
would be the parameter.
I configured the 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 }
);
routes.MapRoute("index", "Check/{id}", new { controller = "Check", action = "Indice", id = UrlParameter.Optional });
}
Controller:
public class CheckController : Controller
{
private Check _check;
public ActionResult Index()
{
//_check.NumberOfregistrationUser = Convert.ToInt16(numberOfregistrationUser);
return View();
}
public ActionResult Indice(long numberOfregistrationUser)
{
_check.NumberOfregistrationUser = Convert.ToInt16(numberOfregistrationUser);
return Content(Convert.ToString(_check.NumberOfregistrationUser));
}
}
A question: why ask for the parameter as
long
and then convert it toshort
?– Jéf Bueno
That I adjusted. I left all as int
– Vinícius
great, now just change the name of the parameter and go to hug.
– Jéf Bueno