MVC 模式在提交失败时会丢失其样式



我有一个关于父表单的部分,它被声明为 Modal。最初,模态按预期显示,但是,在我按下表单上的提交按钮后,它会按预期命中我的 mvc 控制器方法帖子。在控制器中,可能会发生错误,此时我将错误添加到模型警报属性并返回视图。形式和错误显示,但它似乎失去了所有样式。模态最初显示为渲染部分,但在控制器中,我将其作为视图而不是部分视图返回,因此认为这可能是问题所在,但这没有任何区别。所以接下来,我认为这是因为模态需要的主样式表是在父级上声明的,并且因为我使用的是模态,所以可能在回来时不再引用样式表,所以我在模态中明确引用了样式表,但这也没有区别。我现在有点不知所措。

视图在GET 操作调用它之后呈现。 使用引导模式。 在模态中,有一个调用 POST 的提交按钮,并调用标记为 HTTPPost 的控制器操作。 帖子后,将重新应用样式。

视图

@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index12</title>
<style type="text/css">
.keepStyle {
background-color: antiquewhite;
font: italic small-caps bold 44px Georgia, sans-serif;
}
</style>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
</head>
<body>
@*https://getbootstrap.com/docs/4.3/components/modal/*@
<div class="keepStyle">This div style remains after postback</div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
@using (Html.BeginForm())
{
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">(Post)Save changes</button>
</div>
</div>
</div>
</div>
}
</body>
</html>

控制器

public class HomeController : Controller
{
[HttpPost]
public ActionResult Index12()
{
return View();
}
public ActionResult Index12(int? id)
{
return View();
}

最新更新