asp.net 核心中关闭模态表单后如何刷新父页面
How to refresh the Parent page after you close the modal form in asp.net core
我正在使用 asp.net 核心 mvc 5 和 EF 核心 5。
我有一个页面,当按下按钮时,会弹出一个模式窗体。然后用户可以创建一个新人。当用户然后在模态表单上按下提交时,该人将被创建并链接到一个中心。我希望刷新父页面,以便显示新人。下面的代码是我目前的代码。
主页上的按钮是
<button type="button" class="close ml-3 mb-3"
data-toggle="ajax-modal" data-target="#personModal"
data-url="@Url.Action("Create", new { id = Model.Id })"
title="Click to change Person Responsible">
+
</button>
我用下面的javascript打开模态-
$(function () {
var placeHolderElement = $('#PlaceHolderHere');
$('button[data-toggle="ajax-modal"]').click(function (event) {
var url = $(this).data('url');
$.get(url).done(function(data) {
placeHolderElement.html(data);
placeHolderElement.find('.modal').modal('show');
})
})
})
我使用以下方式提交模态表单 -
<input type="submit" value="Submit" name="Submit" class="btn btn-success float-right" id="SubmitForm" />
在我的控制器中 -
[HttpGet]
public IActionResult Create(int id)
{
List<Title> titleList = _titleRepository.Titles.ToList();
ViewBag.TitleList = titleList;
var personListViewModel = new PersonListViewModel
{
persons = _personRepository.Persons,
person = new Person(),
vaccinationCentreId = id
};
return PartialView("_PersonModalPartial", personListViewModel);
}
[HttpPost]
public ActionResult Create(PersonListViewModel pers)
{
_personRepository.CreatePerson(pers.person);
Person newPers = _personRepository.GetPersonByName(pers.person.Forename, pers.person.Surname);
VaccinationCentre vaccCentre = _vaccCentreRepository.GetVaccinationById(pers.vaccinationCentreId);
vaccCentre.PersonResponsableId = newPers.Id;
_vaccCentreRepository.UpdateVaccinationCentre(vaccCentre);
return View("Details", vaccCentre.Id);
}
我的详细信息代码 -
public IActionResult Details(int id)
{
var vaccCentre = _vaccCentreRepository.GetVaccinationById(id);
if (vaccCentre == null)
{
return NotFound();
}
List<Title> titleList = _titleRepository.Titles.ToList();
ViewBag.TitleList = titleList;
List<HealthBoard> healthBoardList = _healthBoardRepository.HealthBoards.ToList();
ViewBag.HealthBoardList = healthBoardList;
List<CentreType> centreTypeList = _centreTypeRepository.CentreTypes.ToList();
ViewBag.CentreTypeList = centreTypeList;
List<VaccinationAvailableTo> vaccAvailableToList = _availableToRepository.VaccinationAvailableTos.ToList();
ViewBag.VaccAvailableToList = vaccAvailableToList;
List<Person> personList = _personRepository.Persons.ToList();
ViewBag.PersonList = personList;
return View(vaccCentre);
}
[HttpPost]
public ActionResult Details(VaccinationCentre vaccCentreModel)
{
if (!ModelState.IsValid)
{
return View(vaccCentreModel);
}
_vaccCentreRepository.UpdateVaccinationCentre(vaccCentreModel);
return RedirectToAction("Index", "Admin");
}
我想要实现的是,当创建 Post 完成时,详细信息(int Id)是 运行 刷新页面。但它正在尝试 运行 详细信息(VaccinationCentre vaccCentreModel)。
我基本上希望父 pge 刷新新数据。
有人能帮忙吗?
我想通了 -
我用了-
$.get("/VaccinationCentre/Details/" + $("#vaccCentreId").val()).done(function (data) {
placeHolderElement.find('.modal').modal('hide')
location.reload();
})
我正在使用 asp.net 核心 mvc 5 和 EF 核心 5。
我有一个页面,当按下按钮时,会弹出一个模式窗体。然后用户可以创建一个新人。当用户然后在模态表单上按下提交时,该人将被创建并链接到一个中心。我希望刷新父页面,以便显示新人。下面的代码是我目前的代码。
主页上的按钮是
<button type="button" class="close ml-3 mb-3"
data-toggle="ajax-modal" data-target="#personModal"
data-url="@Url.Action("Create", new { id = Model.Id })"
title="Click to change Person Responsible">
+
</button>
我用下面的javascript打开模态-
$(function () {
var placeHolderElement = $('#PlaceHolderHere');
$('button[data-toggle="ajax-modal"]').click(function (event) {
var url = $(this).data('url');
$.get(url).done(function(data) {
placeHolderElement.html(data);
placeHolderElement.find('.modal').modal('show');
})
})
})
我使用以下方式提交模态表单 -
<input type="submit" value="Submit" name="Submit" class="btn btn-success float-right" id="SubmitForm" />
在我的控制器中 -
[HttpGet]
public IActionResult Create(int id)
{
List<Title> titleList = _titleRepository.Titles.ToList();
ViewBag.TitleList = titleList;
var personListViewModel = new PersonListViewModel
{
persons = _personRepository.Persons,
person = new Person(),
vaccinationCentreId = id
};
return PartialView("_PersonModalPartial", personListViewModel);
}
[HttpPost]
public ActionResult Create(PersonListViewModel pers)
{
_personRepository.CreatePerson(pers.person);
Person newPers = _personRepository.GetPersonByName(pers.person.Forename, pers.person.Surname);
VaccinationCentre vaccCentre = _vaccCentreRepository.GetVaccinationById(pers.vaccinationCentreId);
vaccCentre.PersonResponsableId = newPers.Id;
_vaccCentreRepository.UpdateVaccinationCentre(vaccCentre);
return View("Details", vaccCentre.Id);
}
我的详细信息代码 -
public IActionResult Details(int id)
{
var vaccCentre = _vaccCentreRepository.GetVaccinationById(id);
if (vaccCentre == null)
{
return NotFound();
}
List<Title> titleList = _titleRepository.Titles.ToList();
ViewBag.TitleList = titleList;
List<HealthBoard> healthBoardList = _healthBoardRepository.HealthBoards.ToList();
ViewBag.HealthBoardList = healthBoardList;
List<CentreType> centreTypeList = _centreTypeRepository.CentreTypes.ToList();
ViewBag.CentreTypeList = centreTypeList;
List<VaccinationAvailableTo> vaccAvailableToList = _availableToRepository.VaccinationAvailableTos.ToList();
ViewBag.VaccAvailableToList = vaccAvailableToList;
List<Person> personList = _personRepository.Persons.ToList();
ViewBag.PersonList = personList;
return View(vaccCentre);
}
[HttpPost]
public ActionResult Details(VaccinationCentre vaccCentreModel)
{
if (!ModelState.IsValid)
{
return View(vaccCentreModel);
}
_vaccCentreRepository.UpdateVaccinationCentre(vaccCentreModel);
return RedirectToAction("Index", "Admin");
}
我想要实现的是,当创建 Post 完成时,详细信息(int Id)是 运行 刷新页面。但它正在尝试 运行 详细信息(VaccinationCentre vaccCentreModel)。
我基本上希望父 pge 刷新新数据。
有人能帮忙吗?
我想通了 -
我用了-
$.get("/VaccinationCentre/Details/" + $("#vaccCentreId").val()).done(function (data) {
placeHolderElement.find('.modal').modal('hide')
location.reload();
})