Route problem with MVC 5 C #

0

I already researched, I spent 2 hours burning my skull but I did not find a solution. Has anyone ever had this problem?

I have the following link:

link

Controller -> Fabricante
Action -> EditarRegistro
Param01 ->53
Param02 ->1
Param03 ->4
...
Param05 -> 13.

My route is configured as follows:

  ///ROTAS PARA FABRICANTE
            routes.MapRoute(
                    name: "EditarFabricante",
                    url: "{controller}/" +
                         "{action}/" +
                         "{org_tab_in_codigo}/" +
                         "{org_pad_in_Codigo}/" +
                         "{org_in_codigo}/" +
                         "{Org_Tau_In_Codigo}/" +
                         "{vFab_In_Codigo}/" +
                         "{Alf_In_codigo}",
                    defaults: new
                    {
                        controller = "Fabricante",
                        action = "EditarRegistro",
                        org_tab_in_codigo = UrlParameter.Optional,
                        org_pad_in_Codigo = UrlParameter.Optional,
                        org_in_codigo = UrlParameter.Optional,
                        Org_Tau_In_Codigo = UrlParameter.Optional,
                        vFab_In_Codigo = UrlParameter.Optional,
                        Alf_In_codigo = UrlParameter.Optional
                    });

My controller is configured:

    [Route("EditarFabricante")]
    public ActionResult EditarRegistro(int Org_Tab_In_Codigo,
                                       int Org_Pad_In_Codigo,
                                       int Org_In_Codigo,
                                       string Org_Tau_In_Codigo,
                                       string vFab_In_Codigo,
                                       int Alf_In_Codigo)
    {
        ViewBag.NotView = ViewData.vNotView;
        var appFabricante = new WebEstFabricanteAplicacao();
        var webFabricante = appFabricante.ListarUmRegistrodaOrganizacao(Org_Tab_In_Codigo,
                                                                        Org_Pad_In_Codigo,
                                                                        Org_In_Codigo,
                                                                        Org_Tau_In_Codigo,
                                                                        int.Parse(vFab_In_Codigo.ToString()),
                                                                        Alf_In_Codigo);

        return View(webFabricante);
    }

[EDIT]

My button to edit the registry is as follows:

                                                       <a href="@Url.RouteUrl("EditarFabricante", 
                                    new {action = "EditarRegistro",
                                    org_tab_in_codigo = item.Org_Tab_In_Codigo,
                                    org_pad_in_Codigo = item.Org_Pad_In_Codigo,
                                    org_in_codigo = item.Org_In_Codigo,
                                    Org_Tau_In_Codigo = item.Org_Tau_St_Codigo,
                                    vFab_In_Codigo = item.Fab_In_Codigo,
                                    Alf_In_codigo = item.Alf_In_Codigo})"
                               title="Editar Registro"
                               onclick="Loading();"
                               class="btn btn-primary">
                                <i class="fa fa-edit"></i>
                            </a>

[/ EDIT]

Clicking the button displays the error:

IcannotdecipherwhymycontrollerisgettingthevalueofvFAB_IN_CODIGOasnull,whichisidentifiedintheURL.

[EDITION]

NowIdiscoveredthattheproblemoccursinthesecondROUTEcreated,whenIcallthefirstcustomROUTEthesystemexecutesnormally,butwhenexecutinganotherROUTEwiththesameparametersthesystempresentsthenullparametererror.

///ROTASPARAFABRICANTEroutes.MapRoute(name:"EditarFabricante",
                url: "{controller}/" +
                     "{action}/" +
                     "{org_tab_in_codigo}/" +
                     "{org_pad_in_Codigo}/" +
                     "{org_in_codigo}/" +
                     "{Org_Tau_In_Codigo}/" +
                     "{vFab_In_Codigo}/" +
                     "{Alf_In_codigo}",
                defaults: new
                {
                    controller = "Fabricante",
                    action = "EditarRegistro",
                    org_tab_in_codigo = UrlParameter.Optional,
                    org_pad_in_Codigo = UrlParameter.Optional,
                    org_in_codigo = UrlParameter.Optional,
                    Org_Tau_In_Codigo = UrlParameter.Optional,
                    vFab_In_Codigo = UrlParameter.Optional,
                    Alf_In_codigo = UrlParameter.Optional
                });


        routes.MapRoute(
                name: "ExcluirFabricante",
                url: "{controller}/{action}/{org_tab_in_codigo}/{org_pad_in_Codigo}/{org_in_codigo}/{Org_Tau_In_Codigo}/{vFab_In_Codigo}/{Alf_In_codigo}",
                defaults: new
                {
                    controller = "Fabricante",
                    action = "ExcluirRegistro",
                    org_tab_in_codigo = UrlParameter.Optional,
                    org_pad_in_Codigo = UrlParameter.Optional,
                    org_in_codigo = UrlParameter.Optional,
                    Org_Tau_In_Codigo = UrlParameter.Optional,
                    vFab_In_Codigo = UrlParameter.Optional,
                    Alf_In_codigo = UrlParameter.Optional
                });

Running the first route:

ClickingusuallycallsfortheeditROUTE.

Nowwhenyouclickdeletethatcallsthesecondroutewiththesameparameters,butActionotherthantheerror.

Am I doing it wrong?

[/ EDITION]

    
asked by anonymous 08.06.2018 / 15:56

1 answer

0

I came to this solution, I'm not sure if it's the right pooooorem ....

I've modified the two ROUTES :

        ///ROTAS PARA FABRICANTE
        routes.MapRoute(
                name: "EditarFabricante",
                url: "{controller}/" +
                     "{action}/" +
                     "{org_tab_in_codigo}/" +
                     "{org_pad_in_Codigo}/" +
                     "{org_in_codigo}/" +
                     "{org_tau_in_codigo}/" +
                     "{fab_in_codigo}/" +
                     "{alf_in_codigo}",
                defaults: new
                {
                    controller = "Fabricante",
                    action = "EditarRegistro"
                });


        routes.MapRoute(
                name: "ExcluirFabricante",
                url: "{controller}/" +
                     "{action}/" +
                     "{org_tab_in_codigo}/" +
                     "{org_pad_in_Codigo}/" +
                     "{org_in_codigo}/" +
                     "{org_tau_in_codigo}/" +
                     "{fab_in_codigo}/" +
                     "{alf_in_codigo}",
                defaults: new
                {
                    controller = "Fabricante",
                    action = "ExcluirRegistro"
                });

Before I was passing the parameters directly to the ROTA , I took the parameters keeping the URL normally. Now I make the route modification directly on the controller .

    [Route("Fabricante/EditarRegistro/{org_tab_in_codigo}/{org_pad_in_Codigo}/{org_in_codigo}/{org_tau_in_codigo}/{fab_in_codigo}/{alf_in_codigo}")]
public ActionResult EditarRegistro(int org_tab_in_codigo,
                                           int org_pad_in_Codigo,
                                           int org_in_codigo,
                                           string org_tau_in_codigo,
                                           int fab_in_codigo,
                                           int alf_in_codigo)
        {
            ViewBag.NotView = ViewData.vNotView;
            var appFabricante = new WebEstFabricanteAplicacao();
            var webFabricante = appFabricante.ListarUmRegistrodaOrganizacao(org_tab_in_codigo,
                                                                            org_pad_in_Codigo,
                                                                            org_in_codigo,
                                                                            org_tau_in_codigo,
                                                                            fab_in_codigo,
                                                                            alf_in_codigo);

            return View(webFabricante);
        }

So he accepted the ROUTES :

link

link

And not getting lost and passing null value to integer parameter.

Thank you all.

    
08.06.2018 / 22:13