Action is not receiving the value of the parameter

0

In the code below I'm 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. However Action takes Null, not the parameter value.

@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" />
                }
            }

    
asked by anonymous 06.11.2015 / 12:43

1 answer

1

Your problem is that you do not have the route setting in your RouteConfig.cs file, 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 to this:

<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/terapeutas/showfoto?id=2 .

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

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 way it is.

    
06.11.2015 / 13:26