Action is not receiving the value of the parameter

Asked

Viewed 39 times

0

In the code below I am trying to pass a parameter to an Action. The action is being called and the value of the parameter is also being assigned to Url. But Action takes Null, not the value of the parameter.

@using (Html.BeginForm("Buscar", "Terapeutas", FormMethod.Post, htmlAttributes: new { @id = "form1", @name = "form1" }))
            {
                @Html.ValidationSummary(true)

                foreach (var item in Model.Terapeutas)
                {
                    <img src="/Terapeutas/ShowFoto/@item.ID_TERAPEUTA" class="img-circle" alt="Foto Terapeuta" width="120" height="120" />
                }
            }

inserir a descrição da imagem aqui

  • How are you calling the Action, could add code?

  • <img src="/Therapists/Showfoto/@item.ID_TERAPEUTA" class="img-Circle" alt="Photo Therapist" width="120" height="120" />

  • Through the @Randrade URL

  • 1

    Have you changed your routeConfig? If not, try this route here: /Terapeutas/[email protected]_TERAPEUTA

  • You are the guy @Randrade .. It worked blz.. Valew

  • I added an answer explaining better how it works.

Show 1 more comment

1 answer

1


Your problem is that you do not have the route configuration in your file RouteConfig.cs, so you can not pass the URL this way. To solve your problem, you can pass the parameter by or configure your route.

With queryString just change your src for that reason:

<img src="/Terapeutas/[email protected]_TERAPEUTA" class="img-circle" alt="Foto Terapeuta" width="120" height="120" />

Note that now your url will look like this: www.domain.com/therapists/showfoto? id=2.

To set your route and continue using the way it is, just add this to your file RouteConfig.cs.

routes.MapRoute(
            name: "Fotos",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Terapeutas", action = "ShowFoto", id = UrlParameter.Optional }
        );

This way you will be able to access using the form you are.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.