Click here to Skip to main content
15,868,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Actually i have one registration form with multiple drop down list and one single button

How can we call those dropdownlist binding on single Actioneresult.

And how can we call submit button event in actionresult.

In asp.net we can call on pageload event like that let me know in MVC razor???
Posted
Comments
Nathan Minier 16-Sep-14 9:11am    
I'm a little confused. As long as the Dropdowns are form elements they should submit alongside every other form element. Your form is an object and that object is passed (in whole) as an argument to the controller.

what is it that you're trying to do that you're unable to?

1 solution

You can Load your dropdown list in index method of your controller And Use ViewData to get data in page.

Example:
ViewData["List1"] = new SelectList(listfromdb, "firstListID", "Name");
ViewData["List2"] = new SelectList(ListfromDb, "SecondListID", "Name");

And Get this in razor view using MVC htmlhelper:
Check html helper more detail
@Html.DropDownList("drpFirstID", (IEnumerable<selectlistitem>)ViewData["List1"], "", new { @id = "drpFirstID"})
@Html.DropDownList("drpSecondID", (IEnumerable<selectlistitem>)ViewData["List1"], "", new { @id = "drpSecondID"})


And to submit your page as usual:
$('#btnLink').click(function(){
    var values =
     {
        "FirstID": $('#drpFirstID').val(),
        "SecondID": $('#drpSecondID').val(),
     };
$.post("ActionName", "ControllerName", values, function(data)
     {
        if(data)
          {
              //do something
          }
        else
         {
            //do something
         } 
     })
});

Or You can submit your page</selectlistitem></selectlistitem>
 
Share this answer
 
v2

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