Advertisement
ziyasal

ASP.NET MVC jquery checkboxlist post

Nov 29th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1.  public class TestModel
  2.     {
  3.         public string[] Values { get; set; }
  4.     }
  5.  
  6.     public class HomeController : Controller
  7.     {    
  8.         public ActionResult TestPost()
  9.         {
  10.             return View();
  11.         }
  12.         public void Test2(TestModel model)
  13.         {
  14.       //do something
  15.         }
  16.     }
  17.  
  18. /*
  19.  
  20. @model StackOverflow.Controllers.TestModel
  21.  
  22. <script src="~/Scripts/jquery-1.7.1.js"></script>
  23. <script type="text/javascript">
  24.     $(document).ready(function () {
  25.         $('#someButton').click(function () {
  26.             $.ajax({
  27.                 url: '@Url.Action("Test2")',
  28.                 type: 'POST',
  29.                 data: $("#myForm").serialize()
  30.             });
  31.         });
  32.     });
  33. </script>
  34.  
  35. @using (Html.BeginForm("Test2", "Home", FormMethod.Post, new { id = "myForm" }))
  36. {
  37.     @Html.ValidationSummary(true)
  38.  
  39.     <fieldset>
  40.         <legend>TestModel</legend>
  41.         <div id="MyDiv">
  42.             <input type="checkbox" name="Values" value="test1" />
  43.             <input type="checkbox" name="Values" value="test2" />
  44.             <input type="checkbox" name="Values" value="test3" />
  45.         </div>
  46.         <p>
  47.             <input type="button" value="Create" id="someButton" />
  48.         </p>
  49.     </fieldset>
  50. }
  51. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement