【发布时间】:2021-11-23 19:55:50
【问题描述】:
我在 VS2019 社区中使用 ASP.NET Core 5 MVC。
我的视图太长了,所以我把它分成几个部分,导航栏中的每个链接都会将用户引导到特定的部分。最后一个部分称为[联系人],此部分用户将添加他的数据和消息,然后单击[发送]。单击按钮后,我想留在同一个地方而不进一步,因为我会查看一个包含他的操作结果的跨度,以感谢他与我们联系。
我使用了这个代码:
// POST: CompController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(MInbox newRecord)
{
string currentSection = "/#contact";
TempData["Result"] = "0";
try
{
if (ModelState.IsValid)
{
OperSucceeded = repo_Inbox.Add(newRecord);
if (OperSucceeded == 1)
{
TempData["Result"] = "1";
return RedirectPreserveMethod(currentSection);
}
}
return RedirectToAction(currentSection);
}
catch (Exception ex)
{
TempData["Result"] = "2";
return RedirectToAction(currentSection);
}
}
这个工作上帝,但是页面重新加载然后归结为[联系]部分,我希望防止重新加载。
谢谢
【问题讨论】:
标签: asp.net-core-mvc asp.net-core-5.0