How to get the value of an Html.DropDownList to pass its value as a parameter to a partial view in MVC asp.net

2

I have the following dropdownlist, which shows the values 5,10 and 15:

<%     Dim listItems = New List(Of ListItem) From { _
        New ListItem() With { _
            .Text = "5", _
            .Value = 5 _
        }, _
        New ListItem() With { _
            .Text = "10", _
            .Value = 10 _
        }, _
        New ListItem() With { _
            .Text = "15", _
            .Value = 15 _
        } _
    }
%>
<%: Html.DropDownList("listado_noticia_length", New SelectList(listItems, "Value", "Text"), New With {Key .[class] = "form-control estilo_dropdownlist input-sm", Key .[onchange] = "javascript:registro_mostrar();"})%>

but I need to pass the selected value of the DropDownList (in this case its id would be lista_noticia_length) to a parameter of this partial view, specifically to the variable cant_filas:

<%: Html.Action("partialListadoNoticia", "Noticias", New With {.pag = 1, .cant_filas = recibir el valor del dropdownlist listado_noticia_length ¿como?})%>

I do not know how I would send the value of the dropdownlist as a parameter to a variable in the partial view. Syntactically I do not know. I need to reference the value of dropdownlist, such as     <%: Dim value_dropdownlist_selected = list_noticia_length.selectValue% >

That would be my question. Thanks again.

    
asked by Danilo 15.05.2016 в 02:47
source

1 answer

2

You will not be able to pass the value of the control because at the moment you need it is not even rendered yet, it is more to define the Html.Action() is server-side code, the dropdownlist as a control does not yet exist

What you could do is take the value from the list of items

<%: Html.Action("partialListadoNoticia", "Noticias", New With {.pag = 1, .cant_filas = listItems[0].Value })%>

As you will see using listItems[0].Value you do not leave the value fixed and you take it from the same source as the dropdownlist

    
answered by 16.05.2016 / 07:32
source