@ Html.DropDownList

0

good day. I am currently working with .net and I have problem I want to send information to a method of a controller by means of a @ Html.ActionLink , this method asks me for two values which are the LevelId that I have no problem in passing it and I have to pass the selection you have in @ Html.DropDownList the problem is that I could not know how to pass the information. I tried to put an id @ Html.DropDownList but it does not work since the @ Html.ActionLink can not find it.

This is the @ Html.DropDownList

<div class="container">
<div class="form-group">
    <h3>Anno lectivo</h3>
    <div class="col-md-10">
        @Html.DropDownList("AnnoLectivoId", null, htmlAttributes: new { @class = "form-control" , @id = "AnnoLectivoId" })           
    </div>
</div>

The table shows an information and for each row there is a @ Html.ActionLink that allows to direct this information to a method in a controller, I want to attach the information of the @ Html.DropDownList that would be the id of what is selected.

<table class="table table-striped">
<tr>
    <th>
        @Html.DisplayNameFor(model => model.NameLevel)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.DescriptionLevel)
    </th>
    <th>
        Acciones
    </th>
</tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.NameLevel)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DescriptionLevel)
        </td>
        <td>
            @Html.ActionLink("Detalle", "ChangeStatus", "Enroll_Student", new { id = item.LevelId }, new { @class = "btn btn-info" })
        </td>
    </tr>
}

    
asked by Jhon Alexander Jimenez Morales 28.11.2018 в 16:32
source

1 answer

2

If you want to take a value dynamically in an ActionLink you will have to use javascript or better jquery

@Html.ActionLink("Detalle", "ChangeStatus", "Enroll_Student",
                   new { id = item.LevelId,  AnnoLectivo = "param1"}, new { @class = "btn btn-info", id="detalle" })

Validate how the parameters are defined and then replace them

<script>
    $(function(){

       $("#detalle").click(function(){ 

           val AnnoLectivo = $("#AnnoLectivoId").val();

           this.href = this.href.replace("param1", AnnoLectivo);
       })
    })

</script>

Although it would be easier if you make a submit and pass the values as part of the body of the form

ASP.Net MVC: Pass (Send) DropDownList Selected Value to Controller using Html.ActionLink

    
answered by 28.11.2018 в 17:12