Pass (Send) DropDownList selected value to Controller using jQuery Ajax in ASP.Net MVC

Last Reply on Apr 04, 2019 03:39 AM By dharmendr

Posted on Apr 03, 2019 11:57 PM

Hello everyone

I have a dropdownlistfor() with a in my view and I have a button type=submit being used by a different control. I added another button and I would like to get my selected value from my dropdownlistfor

so I can use it in my button click.

Here is my view setup

@using (Html.BeginForm())
{
    <div class="panel panel-default">
        <div class="panel-heading">Choose Administrator</div>
        <div class="panel-body">
            @if (TempData["Success"] != null) {}
            @if (TempData["Error"] != null) {}
            @Html.AntiForgeryToken()
            <div class="row">
                <div class="col-md-4">@*This is the value I want *@
                    @Html.DropDownListFor(a => a.UserId,
                     new SelectList(Model.lstAdmins, "UserId", "Name"),
                     new { @class = "form-control" })
                    @Html.ValidationMessageFor(a => a.UserId)
                </div>
            </div>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-body">
        <div class="clearfix"></div>
        <div class="row">
            @for(var i = 0; i < Model.lstUsers.Count(); i++)
            {
                <div class="col-md-4">
                    <div>
                        @Html.CheckBoxFor(u => Model.lstUsers[i].SelectedUsers)
                        <label>
                            @Html.DisplayFor(u => Model.lstUsers[i].Name)
                            @Html.HiddenFor(u => Model.lstUsers[i].UserId)
                            @Html.HiddenFor(u => Model.lstUsers[i].Name)
                        </label>
                    </div>
                </div>
            }
        </div>
        <div class="row">
            <div class="form-group">
                <div class="col-md-offset-0 col-md-12">
                   <input type="submit" value="Assign Role" class="btn btn-success"/>

@*THIS IS THE BUTTON I WANT THE DROPDOWNLISTFOR VALUE FOR *@

<button type="button" onclick="@Url.Action("RemoveAdmin", "SuperAdmin")" 
    value="Remove Role" class="btn btn-danger"></button>

 

This question does not have replies that have been liked.