Click here to Skip to main content
15,941,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Alll,

I wanted to pass dropdownlist selected value in Ajax.BeginForm with some other multiple controls to my Controller,

Here is my code,anyone's help or suggestions are appreciated

C#
@using (Ajax.BeginForm("AddNewStore", "StoreRegistration", new AjaxOptions { HttpMethod = "POST", OnSuccess = "successOfAddition", OnFailure = "failureOfAddition" }, new { id = "addStoreRegisterForm" }))
                {
                    <div class="form-group col-md-6">
                        <div class="form-group">                           
                            @Html.DropDownListFor(x => x.StoreRegistrationAssociation.StoreIdentity, new SelectList(Model.StoreRegistrationAssociation.StoreIdentity, "Code", "Name", Model.StoreRegistrationAssociation.StoreIdentity), "Please Make a Selection", new { @class = "form-control", placeholder = "Please Make a Selection" })
                            @Html.ValidationMessageFor(x => x.StoreRegistrationAssociation.StoreIdentity)
                        </div>
                    </div>
                        <div class="form-group col-md-6">
                            <div class="form-group">
                                <!--[if gte IE 9]><div class="input-group"><span class="input-group-addon">Store Number</span><![endif]-->
                                @*<input type="text" placeholder="Store Number" value="" name="storeno" class="form-control" />*@
                                <!--[if gte IE 9]></div><![endif]-->
                                @Html.TextBoxFor(x => x.StoreRegistrationAssociation.StoreNumber, new { @class = "form-control", placeholder = "Store Number" })
                                @Html.ValidationMessageFor(x => x.StoreRegistrationAssociation.StoreNumber)
                            </div>
                        </div>
}


HTML
<div class="form-group">
                                    <input type="reset" value="Cancel" />
                                    <button type="submit" class="red-btn" data-dismiss="modal" id="btnRegisterStore">Agree</button>
                                </div>


On my button click i am getting the SelectedIdentity value as Count=0

What I have tried:

I have tried using onchange event in my ajax begin form

function AdditionalsChanged() {
selIdentity = $("#ddlIdentity").val();
$("#ddlIdentity").val(selIdentity);
}

@Html.DropDownListFor(x => x.StoreRegistrationAssociation.StoreIdentity, new SelectList(Model.StoreRegistrationAssociation.StoreIdentity, "Code", "Name", Model.StoreRegistrationAssociation.StoreIdentity), "Please Make a Selection", new { @class = "form-control",id="ddlIdentity", placeholder = "Please Make a Selection" })
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900