Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. LoadBooks();
  4. });
  5.  
  6. function LoadBooks() {
  7. $(".Books").hide();
  8. $(".Books").load("/Books/Edit/<%= Model.AuthorID %>");
  9. $(".Books").show('slow');
  10. }
  11. </script>
  12.  
  13. <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Solution.Controllers.BooksController+BooksViewModel>" %>
  14. <% using (Html.BeginForm(null,null, FormMethod.Post,new { id = "bookform" }))
  15. {%>
  16. <fieldset>
  17. <legend>Books</legend>
  18. <%int i = 0;
  19. foreach (var book in Model.Books)
  20. {%>
  21. <%= book.BookID%>
  22. <%= Html.Hidden("book[" + i + "].BookID", book.BookID) %>
  23.  
  24. <%= Html.DropDownList("book[" + i + "].CatID", new SelectList(Model.Categories, "CatID", "CatTitle", book.CatID))%>
  25. <%= Html.ValidationMessage("CatID", "*")%>
  26.  
  27. <%= Html.TextBox("book[" + i + "].BookTitle", book.BookTitle)%>
  28. <%= Html.ValidationMessage("BookTitle", "*")%>
  29. <br />
  30. <%i++;
  31. } %>
  32. </fieldset>
  33. <% } %>
  34.  
  35. function DoAjaxPostAndMore(btnClicked)
  36. {
  37. var $form = $(btnClicked).parents('form');
  38.  
  39. $.ajax({
  40. type: "POST",
  41. url: $form.attr('action'),
  42. data: $form.serialize(),
  43. error: function(xhr, status, error) {
  44. //do something about the error
  45. },
  46. success: function(response) {
  47. //do something with response
  48. LoadBooks();
  49.  
  50. }
  51. });
  52.  
  53. return false;// if it's a link to prevent post
  54.  
  55. }
  56.  
  57. <input type="button" value="Submit" onclick="DoAjaxPostAndMore(this)"/>
  58.  
  59. <a href="/url/something" onclick="return DoAjaxPostAndMore(this)">linktext</a>
  60.  
  61. var $form = $("#theformid");
  62.  
  63. <a href = "javascript: SaveProperties();">Save properties</a>
  64. SaveProperties() { $('#bevpropform').submit(); }
  65.  
  66. SaveProperties() { $('#bevpropform').submit(); return false; }
  67.  
  68. @using (Ajax.BeginForm("Method", "Controller", new AjaxOptions { HttpMethod = "POST" }))
  69. {
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement