所以,我有一个问题。当我向控制器发送包含所有空数据的请求时,查询正在运行,我可以在我的控制器上调试它,但是当我向查询添加至少一个值时,表单根本停止工作。没有结果,错误等。我使用部分视图跳过添加表单。
布局脚本:
页面底部的所有脚本。
我的ajax开始表格
@model AttanctionTest.Models.TestParam
@using (Ajax.BeginForm("TestParamApply", "Admin", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "PartialViewId" }))
{
@Html.AntiForgeryToken()
if (ViewBag.Action == "Set")
{
<input type="hidden" name="ActionStr" value="Set" />
<p>Добавить запись</p>
}
else
{
<input type="hidden" name="ActionStr" value="Update" />
<p>Изменить запись</p>
}
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.Label("Количество вопросов", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CountQuestion, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CountQuestion, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Время теста", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TimeTest, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TimeTest, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Время появления фигуры", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FigureTime, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FigureTime, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" style="width: 100%;" value="Применить" class="btn btn-default" />
</div>
</div>
</div>
}
我的控制器方法
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult TestParamApply(string ActionStr, TestParam testParam, int? Id)
{
switch (ActionStr)
{
case "Set":
SQLite.Set(testParam);
break;
case "Update":
SQLite.Update(testParam);
break;
case "Delete":
var list = SQLite.Get<TestParam>().Where(x => x.Id == Id).FirstOrDefault();
SQLite.Delete(list);
break;
}
return RedirectToAction("ListView", new { Table = "TestParam" });
}