У меня есть список сообщений, отображаемых через таблицу данных, связанную с базой данных.Для операции изменения строки моего объекта данных я использую модалы, и когда я изменяю строку моего объекта данных, база данных обновляется как моя база данных, но не как мой модал.Модал обновляется только если я обновляю страницу.Можно ли будет динамически обновлять мод после внесения изменений в закрытие модального режима?
Мне удается отображать мой мод и изменять мою базу данных, а также динамические данные с помощью ajax.Я попытался изменить содержание модального с обновлением.
введите описание изображения здесь , введите описание изображения здесь , введите описание изображения здесь , введите описание изображения здесь , введите описание изображения здесь
@Html.BeginForm("Edit", "Nouvelle", null, FormMethod.Post, new { onsubmit = "return SubmitForm(this)" }))
<div class="form-group">
@Html.LabelFor(model => model.message, "Titre", new { @class = "control-label" })
@Html.EditorFor(model => model.titre, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.titre)
</div>
<div class="form-group">
@Html.LabelFor(model => model.message, "Message", new { @class = "control-label" })
@Html.TextAreaFor(model => model.message, new { @class = "form-control", @style = "height: 150px; max-width: 100%" })
@Html.ValidationMessageFor(model => model.message)
</div>
<div class="form-group">
@Html.LabelFor(model => model.auteur, "Auteur", new { @class = "control-label" })
@Html.EditorFor(model => model.auteur, new { htmlAttributes = new { @class = "form-control", disabled = "disabled", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.auteur)
</div>
<div class="form-group">
@Html.LabelFor(model => model.date_publication, "Dernière date de publication", new { @class = "control-label" })
@Html.EditorFor(model => model.date_publication, new { htmlAttributes = new { @class = "form-control", disabled = "disabled", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.date_publication)
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Retour</button>
<button type="submit" class="btn btn-primary btn-ok">Modifier</button>
</div>
}
× Модификация
var PopupForm = function (id) {
var url = "/Nouvelle/EditId?id=" + id;
$("#modificationContent").load(url, function () {
$("#modification").modal("show");
})
}
function SubmitForm(form) {
$.ajax({
type: "POST",
url: "/Nouvelle/Edit",
data: $(form).serialize(),
success: function (response) {
if (response.success) {
$("#modification").modal("hide");
dataTable.ajax.reload();
toastr.success("Votre news a bien été modifiée !");
} else {
toastr.error("Les champs titre et/ou message(s) doive(nt) être rempli(s) !");
}
}
});
return false;
}
[HttpPost]//controller
public ActionResult Edit(News tempNews)
{
if (tempNews.titre != null && tempNews.message != null)
{
string test = tempNews.titre.Trim();
if (tempNews.titre.Trim() != "" && tempNews.message.Trim() != "")
{
using (PortailEntities db = new PortailEntities())
{
if (ModelState.IsValid && tempNews != null)
{
var v = db.News.Where(n => n.id_news == tempNews.id_news).FirstOrDefault();
v.titre = tempNews.titre.Trim();
v.message = tempNews.message.Trim();
v.auteur = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
v.date_publication = DateTime.Now;
}
db.SaveChanges();
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
}
}
return Json(new { success = false }, JsonRequestBehavior.AllowGet);
}
Я хотел бы динамически обновить модальный тип данных.