Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(document).ready(function() {
- LoadBooks();
- });
- function LoadBooks() {
- $(".Books").hide();
- $(".Books").load("/Books/Edit/<%= Model.AuthorID %>");
- $(".Books").show('slow');
- }
- </script>
- <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Solution.Controllers.BooksController+BooksViewModel>" %>
- <% using (Html.BeginForm(null,null, FormMethod.Post,new { id = "bookform" }))
- {%>
- <fieldset>
- <legend>Books</legend>
- <%int i = 0;
- foreach (var book in Model.Books)
- {%>
- <%= book.BookID%>
- <%= Html.Hidden("book[" + i + "].BookID", book.BookID) %>
- <%= Html.DropDownList("book[" + i + "].CatID", new SelectList(Model.Categories, "CatID", "CatTitle", book.CatID))%>
- <%= Html.ValidationMessage("CatID", "*")%>
- <%= Html.TextBox("book[" + i + "].BookTitle", book.BookTitle)%>
- <%= Html.ValidationMessage("BookTitle", "*")%>
- <br />
- <%i++;
- } %>
- </fieldset>
- <% } %>
- function DoAjaxPostAndMore(btnClicked)
- {
- var $form = $(btnClicked).parents('form');
- $.ajax({
- type: "POST",
- url: $form.attr('action'),
- data: $form.serialize(),
- error: function(xhr, status, error) {
- //do something about the error
- },
- success: function(response) {
- //do something with response
- LoadBooks();
- }
- });
- return false;// if it's a link to prevent post
- }
- <input type="button" value="Submit" onclick="DoAjaxPostAndMore(this)"/>
- <a href="/url/something" onclick="return DoAjaxPostAndMore(this)">linktext</a>
- var $form = $("#theformid");
- <a href = "javascript: SaveProperties();">Save properties</a>
- SaveProperties() { $('#bevpropform').submit(); }
- SaveProperties() { $('#bevpropform').submit(); return false; }
- @using (Ajax.BeginForm("Method", "Controller", new AjaxOptions { HttpMethod = "POST" }))
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement