Eviar view parameter for action

Asked

Viewed 210 times

1

I have a views that lists my users, is basically in the pattern generated by Asp.net mvc with Entity, the data is in a table, and within this table I have a :

@Html.ActionLink("Aprovar cadastro", "Aprovar")

And I have inside the controller Action:

 [HttpGet]
    public ActionResult Aprovar(int? Id)
    {
        if(Id == null){return new HttpStatusCodeResult(HttpStatusCode.BadRequest);}
        else { 
               //A função será implementada aqui
        }
    }

Basically I need to pass the Id of a specific user to this controller, but I’m not succeeding.

Follow my view:

@model IEnumerable<ApegaPet.Models.ApplicationUser>
@{     Layout = "~/Views/Shared/_SideNavbar.cshtml";  }
@{
    ViewBag.Title = "Avaliar_Ong";
}


<h2>Avaliar requisição de cadastro de Ongs</h2>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.nomerazao)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.endereco)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.telefone)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Email)
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.nomerazao)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.endereco)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.telefone)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Email)
            </td>
            <td>
                @Html.ActionLink("Aprovar cadastro", "Aprovar")
            </td>
        </tr>

    }


</table>

1 answer

1


  • For example, this.id item has to necessarily be displayed in the view ?

  • No, @Prostetnicvogonjeltz can be a number chosen by its programming, just need to follow the same nomenclature of new { Id = where the value should be an integer. I put it like this because I imagined it would be him, but, it may be as already said of his programming.

  • @Prostetnicvogonjeltz it is worth remembering that this Id is not mandatory, because its rule allows him to be null, looking out for controller int? Id!

Browser other questions tagged

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