Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 1.09 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ASP.NET MVC 3 - Can We Use Model Binding Over jQuery AJAX Calls?
  2. function getResults(field1, field2, field3) {
  3.    $.get('/Search/GetResults', { id: field1, type: field2, blah: field3 }, function(data) {
  4.       $('#target').html(data);
  5.    });
  6. }
  7.        
  8. [HttpGet]
  9. public PartialViewResult GetResults(int id, int type, string blah)
  10. {
  11.    var model = repository.GetResults(id, type, blah);
  12.    return PartialView("Results", model);
  13. }
  14.        
  15. function getResults(someModel) {
  16.    $.get('/Search/GetResults', { model: someModel }, function(data) {
  17.       $('#target').html(data);
  18.    });
  19. }
  20.        
  21. [HttpGet]
  22. public PartialViewResult GetResults(SearchPreferences prefs)
  23. {
  24.    var model = repository.GetResults(prefs);
  25.    return PartialView("Results", model);
  26. }
  27.        
  28. var field1 = $('#field1').val();
  29. var field2 = $('#field2').val();
  30.        
  31. public class SearchPreferences
  32. {
  33.   public int id { get; set; }
  34.  
  35.   public int type { get; set; }
  36.  
  37.   public string blah { get; set; }
  38. }
  39.        
  40. [HttpGet]
  41. public PartialViewResult GetResults(SearchPreferences prefs)
  42. {
  43.    var model = repository.GetResults(prefs);
  44.    return PartialView("Results", model);
  45. }