Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Controller:
C#
  public ActionResult Create(BookCreat book)
        {
            if (ModelState.IsValid)
            {
                BookShelfEntities bse = new BookShelfEntities();
                BookCreat newBook = new BookCreat();
                newBook.Id = book.Id;
                newBook.BookName = book.BookName;
                newBook.BookAuthour = book.BookAuthour;
                newBook.ISBN = book.ISBN;
                bse.BookCreat.Add(newBook);
                bse.SaveChanges();
                return RedirectToAction("Index");

            }

            return View(book);
        }
  
    }
}

Partial:
C#
<fieldset>
        <div id="partialdiv">
            <p>Partial</p>
            <div class="editor-label">
                @Html.LabelFor(model => model.Id)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Id)
                @Html.ValidationMessageFor(model => model.Id)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.BookName)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.BookName)
                @Html.ValidationMessageFor(model => model.BookName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.BookAuthour)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.BookAuthour)
                @Html.ValidationMessageFor(model => model.BookAuthour)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.ISBN)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.ISBN)
                @Html.ValidationMessageFor(model => model.ISBN)
            </div>
      
                <input id="partialSave" type="submit" value="Create" />
            
        </div>
       </fieldset>

<script>

my simple code
C#
           $(function () {
                $("#partialSave").click(function (e) {
                    e.preventDefault();
                    alert("Partial alert");
                    var book = {
                        Id: $("#Id").val(),
                        BookName: $("#BookName").val(),
                        BookAuthour: $("#BookAuthour").val(),
                        ISBN: $("#ISBN").val(),
                    };
                    $.ajax({
                      type: "POST",
                      url: "@Url.Action("Create", "Default1")",
                        data: JSON.stringify(book),
                        dataType: "json",
                      contentType: "application/json;charset=uft-8",                                         success: function () {
                          alert("succes");
                      },
                      error: function () {
                          alert("hata");
                      }
                  });
                  });
            });
</script>


this is my ajax and simple code but opject didnt give any data and it try to control only null how can i fix it?
How can give the text boxes value i cant solve it how can solve its promlem
Posted
Updated 4-May-15 21:14pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900