javascript - in MVC 5 how to pass selected value to html action in jquery ajax function -


When I select something from the user list, I am using jQuery AJAX to load some data. How can I pass the value of the options selected in the action parameters?

I tried making variables selected value but it says that the name "selectedValue" does not exist.

  & lt; Script & gt; $ (Document) .ready (function () {$ ("# students"). Change (function () {var selectedValue = $ ("# students"). Val (); $ .ajax ({url: '@ url Type "GET", success: function (result) {$ ("# Notifications"). Html (results) (Action) ("Gate Data", "Sample", New {Table = "Student", ID = selected}), ;}});});}) & Lt; / Script & gt;  

Are you using the correct variable? It seems that you are reading the value for selectedValue but try not to use it

  var selectedValue = $ ("# students") . Val (); $ AZ ({url: '@ Url.Action ("GetData", "Sample")? Table = Student & amp; ID =' + Selected Value, Type: "GET", Success: Function (Results) {$ ("# Information "). Html (results);}});  

This is named 2 values ​​named after your GetData action method table and id

  Public Action Gate Data (string table, string id) {//: return something useful}  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -