asp.net mvc - @Html.BeginForm Post value from dropdown Change event instead of a submit button -
I am trying to implement a 'refined' option within my MVC project.
My thoughts on top, I have something like this
+ ---------------------- ---------- ----------------- + | ______ | | Select: | 1 | ▼ || | | | + ------------------------------------------------- +
Where the user can choose a number from the drop down list.
However, in order to post it, it requires 'Submit Button':
+ --------------- --------------------------- ------- + | ______ | | Select: | 1 | ▼ || [Live] | | | + ------------------------------------------------- +
Is there a way to delete this 'GO' button so that it automatically sends this value to the controller when I select a value from the dropdown?
VIEW
& lt; One style = "font-size: big; font-weight: bold; padding-bottom: 50%" & gt; Select: @ Html.DropDownList ("number") & lt; Input type = "submit" value = "go" id = "subBtn" /> gt; & Lt; / A & gt;
Controller
Public Performance Index (string number) {if (! String.isnorocalite (number)) var bays = db.Bays.Include (b = & Gt; B. Products); {Int t = convert toInt32 (number); Bays = bays.Where (x => x.id == t); } Var number = new list & lt; Int & gt; (); Var choice = x by db.Bays command x.ID Select x.ID; Number.AddRange (choice.Distinct ()); ViewBag.Number = new selection list (number); // Returns the list (bays.ToList ()); }
Basically, my query 'drop down can also work as a' submit 'on a selection change, and if so, how to implement it ? '
Yes, you can do this.
1. Make a form with the verb you want to handle, post and place your dropdown in the form.
2. Set the ID for the dropdown, for example, is called 'ProductConverter'.
3. Create a jquery function based on the dropdown on change event.
4. Trigger form form in that function.
$ ("# productcounter"). Change (function () {$ ("Form [0]"). Submit ();});
Comments
Post a Comment