0
I have the following code in my view:
@using (Html.BeginForm("DataAniv", "Mailing", FormMethod.Post))
{
<div class="form-group">
<label for="sel1">Selecione o mês:</label>
<select class="form-control" id="sel1">
<option value="Janeiro">Janeiro</option>
<option value="Fevereiro">Fevereiro</option>
<option value="Março">Março</option>
<option value="Abril">Abril</option>
<option value="Maio">Maio</option>
<option value="Junho">Junho</option>
<option value="Julho">Julho</option>
<option value="Agosto">Agosto</option>
<option value="Setembro">Setembro</option>
<option value="Outubro">Outubro</option>
<option value="Novembro">Novembro</option>
<option value="Dezembro">Dezembro</option>
</select>
</div>
<input class="btn btn-primary" type="submit" value="Gerar">
}
The idea is that once the user makes a selection on this list, "value" is sent to the controller that will execute a logic. However, no matter which way I try, the form always gives the Submit with null value. Is it possible for the code to work this way? Or I must use Javascript or @Html.Dropdownlistfor?
So actually, when I try to send a <input type="text" tag to the controller, I can do it. The problem is with the specific <select> tag, I cannot capture the selected value to send to the controller...
– Nugo Sunes
See that I added your Select in the example, if you are not getting the value of
sel1
and itsController
is because his type is not hitting, the attribute expects astring
with the name of the month or aint
with an id?– Leandro Angelo
@Nugosunes, there was some doubt?
– Leandro Angelo
Sorry, I ended up running out of time to test the implementation! Now that I could do it that was right, the name attribute was missing! Thank you very much.
– Nugo Sunes