How to mix parameters within an ASP.NET Html.BeginForm

1

I have the following Html.BeginForm (Do not take into account if it is incorrect is a legacy code and I can not refactor this now).

using (Html.BeginForm("Confirm", "Download", new { ContributorID = "exemplo"}, FormMethod.Post, new { id = "confirm" })) {
    <div class="form-group">
        <label for="work_select">Selecione uma obra existente:</label>
        <select class="form-control" id="work_select">
            <option value="0" selected="selected">Selecione uma obra</option>
        </select>
    </div>
    <p id="error-message"></p>

    @Html.AntiForgeryToken()
    <div class="inner-addon left-addon">
        <i class="fa fa-download" aria-hidden="true"></i>
        <input type="submit" value="@MainMessages.confirm_your_download" class="button-download" style="width:100%" />
        <br />
    </div>
}

Controller:

[HttpPost]
public ActionResult Confirm(string contributorID,string work_select)

If you noticed there is a parameter being added without using an input new { ContributorID = "exemplo"} , I need this to continue , but <select> is not passing work_select to controller, it gets null , how can I do that?

    
asked by anonymous 23.11.2018 / 22:50

1 answer

2

<select> is not being sent by form because it does not have the name attribute. While id is important for JavaScript in the DOM structure, the <form> controls will only be appended to FormData if they indicate the name attribute or if you manually add them via JavaScript. >

<div class="form-group">
    <label for="work_select">Selecione uma obra existente:</label>
    <select class="form-control" id="work_select" name="work_select">
        <option value="0" selected="selected">Selecione uma obra</option>
    </select>
</div>
    
24.11.2018 / 12:00