我想使用Ajax渲染表。表中的div。我将文本写入文本框,单击按钮并返回带有新文本的表格。 Ajax只执行一次。我点击了按钮,首先它工作正常,文本正在添加到表格中,但它没有工作。我将类型更改为按钮并编写jquery,它不起作用。请帮助我。
<div id="render">
<table>table here</table>
</div>
@using (Ajax.BeginForm("CreateTask", "Admin", new AjaxOptions {UpdateTargetId = "render", HttpMethod = "Post", InsertionMode = InsertionMode.Replace }, new{id = "myForm"}))
{
@Html.TextBox("Text")
@Html.Hidden("ID", item.ID)
<input type="submit" value="Add Task" id="btnSubmit" class="btn btn-success" />
}
public ActionResult CreateTask(int ID, string text)
{
ModelState.Clear();
Project project = db.Projects.FirstOrDefault(p => p.ID == ID);
Tasking task = new Tasking { Name = text, Status = false };
project.Tasks.Add(task);
db.SaveChanges();
//return RedirectToAction("Index", this.db.Projects.ToList());
return PartialView("_PartiaV", db.Projects.ToList());
}
$(document).ready(function () {
$("#btnSubmit").click(function () {
var formdata = $("#myForm").serialize();
$.ajax({
type: "POST",
url: "/Admin/CreateTask",
data: formdata,
success: function () {
}
})
})
})