ajax - ASP.Net MVC 3 Drop Down List -


I am developing an ASP.NET mvc 3 web application, in some of my razor sequences, some text boxes and drop downs The list includes I when the user selects an option from the drop down list, I need a partial view or something like this, to get better without a post back below the drop-down list.

This is, as long as the user selects an option from the drop down list, then I am being sent to a controller for a method, based on this option I execute some arguments, And then return some data in partial view.

I have not really got much experience with AJX, but I think this is a technique I use to cure my problem.

Has anyone ever had to code something similar to what I have described above? And if so, why do I need to use AJAX?

In addition, if any tutorial or code knows the snippets I can look for help, it will be highly appreciated.

Thank you.

UPDATE

I have followed Ryan's answer, but unfortunately I still have some problems. I have created the following JavaScript file, then My view is referenced

  $ (document) .ready (function () {$ ("# myDDL"). Change (ChangeEventOfDDL); ChangeEventOfDDL () (Var dropdownown = $ (' # MyDDL '). Val (); // Alert (dropdown value); $ .ajax ({type: "GET", url:' @ Url.Action ("some partial view", "testAjax"), data: {id : DropDownValue}, success: function (data) {$ ('# someDivToLoadContentTo '). Html (data);}});}});   

View

  Select ID = "myDDL" & gt; & Lt; option & gt; & lt; / option & gt; option value = "1" & gt; F1 & lt; / option & gt; option value = "2" & gt; F2 & Lt; / option & gt; Option value = "3" & gt; ST1  gt; option value = "4"> ST2  & Lt; / select & gt; & lt; div id = "someDivToLoadContentTo" & gt; & lt; / div & gt;   

Then my controller looks like this

  test for public class: AJAX controller: controller {// // GET: / testAjax / LocumEntities reference = new location (); Public Efficiency Some PartialView (int id) {var test = "Hello World"; See Return (Test); }}   

However, my method 'SomePartialView' is never hit. Does anyone know why?

Thank you.

Yes, Ajax will be the easiest thing to use here. There are lots of things around Ajax tutorials, just remember that Ajax is a background post effectively, so whatever you can do, it will usually do with MVC in addition to any existing page.

The way I work to get this, your code will have to do something like this:

  public class SomeController {public ActionResult SomePartialView () {// Return logic ("some partial"); }}   

Your Ajax will do something like this:

  ChangeEventOfDDL () {$ .ajax ({url: '@ Url.Action ("SomePartialView" , "Some"), success: function (data) {$ ('# some dividout content to'). Html (data);}}); }   

I hope that at least a little bit of help is available.

Along with Ajax, you can add a data object to the function, which has been passed as a query string. This means that you can easily send prices with Ajax from your page. Working with the above example, Javascript will be:

  ChangeEventOfDDL () {var dropdownown = $ ('# ddl'). Val (); $ .ajax ({url: '@ Url.Action ("SomePartialView", "some"), data: {id: dropDownValue} success: function (data) {$ (' # someDivToLoadContentTo ') .html (data);} }); }   

The ID value is associated with the parameters of the method in your MVC class:

  public class SomeController {public ActionResult SomePartialView (int id) {// Some arguments var model = MakeModelWithSupplierId (id); See Return ("Some Partition", Model); }}   

And there you have an interactive partial view that is populated with values ​​from your drop down.

Comments