使用ajax调用渲染正确的局部视图

时间:2022-06-01 19:00:19

I have a controller with partial views, for example I have a partial view , like this:

我有一个部分视图的控制器,例如我有一个局部视图,像这样:

[HttpGet]
        [AutorisatieFilter(Rol = "Personeelsdossier | Rekeningen@Lezen")]
        public ActionResult Rekeningen()
        {
            var model = PersoneelsDossierService.GetRekeningLezenModel(Context, HuidigeDienstverbandId,GetMutatieRol(), Gebruiker.DienstverbandId);

            SetMedewerkerSelectie(model);

            model.IsBevoegd = true;

            try
            {
                BeveiligingService.ControleerManagerBevoegdheidVoorDienstverband(Context, Context.Klant.Id, int.Parse(Context.Gebruiker.ExternId), HuidigeDienstverbandId, Gebruiker.DienstverbandId);
            }
            catch(AuthenticationException)
            {
                model.IsBevoegd = false;
            }

            return PartialView("~/Areas/MSS/Views/PersoneelsDossier/Rekeningen.cshtml", model);
            //return View(model);
        }

This is inside the controller name: Personeelsdossier.

这是在控制器名称内:Personeelsdossier。

The view of Rekeningen looks,like this:

Rekeningen的视图看起来像这样:

2 个解决方案

#1


0  

Partial Views do not use the Layout, so they will not include CSS unless you have the CSS in the partial view - They are intended to be render into full views.

部分视图不使用布局,因此除非在局部视图中具有CSS,否则它们将不包括CSS - 它们旨在呈现为完整视图。

Just change the Partial View to a full view if you want to use the layout page, or add your CSS to the Partial View if you want the CSS but no layout...

如果您想使用布局页面,只需将局部视图更改为完整视图,或者如果您想要CSS但没有布局,则将CSS添加到局部视图中...

#2


0  

In our Application, we have special Master pages for Partial Views to include Scripts and CSS for example.

在我们的应用程序中,我们有部分视图的特殊母版页,例如包括脚本和CSS。

1) Create a new Master Page cshtml in Views\Shared folder (for example, PopupMaster.cshtml). It holds a very basic HTML template:

1)在Views \ Shared文件夹中创建一个新的Master Page cshtml(例如,PopupMaster.cshtml)。它拥有一个非常基本的HTML模板:

<!DOCTYPE html>
<html lang="en">
<head>
    <link href="~/Content/some.additional.css" rel="stylesheet">
</head>
<body>
    @RenderBody()

    <script src="maybe.some.additional.script.to.execute.js"></script>
</body>
</html>

2) Instead of return PartialView(...) you can now do return View("MyView", "PopupMaster", myModel);

2)您现在可以返回View(“MyView”,“PopupMaster”,myModel),而不是返回PartialView(...);

This will result in a partialview-like result, but with possibility to provide extra css and scripts

这将导致类似部分视图的结果,但有可能提供额外的css和脚本

#1


0  

Partial Views do not use the Layout, so they will not include CSS unless you have the CSS in the partial view - They are intended to be render into full views.

部分视图不使用布局,因此除非在局部视图中具有CSS,否则它们将不包括CSS - 它们旨在呈现为完整视图。

Just change the Partial View to a full view if you want to use the layout page, or add your CSS to the Partial View if you want the CSS but no layout...

如果您想使用布局页面,只需将局部视图更改为完整视图,或者如果您想要CSS但没有布局,则将CSS添加到局部视图中...

#2


0  

In our Application, we have special Master pages for Partial Views to include Scripts and CSS for example.

在我们的应用程序中,我们有部分视图的特殊母版页,例如包括脚本和CSS。

1) Create a new Master Page cshtml in Views\Shared folder (for example, PopupMaster.cshtml). It holds a very basic HTML template:

1)在Views \ Shared文件夹中创建一个新的Master Page cshtml(例如,PopupMaster.cshtml)。它拥有一个非常基本的HTML模板:

<!DOCTYPE html>
<html lang="en">
<head>
    <link href="~/Content/some.additional.css" rel="stylesheet">
</head>
<body>
    @RenderBody()

    <script src="maybe.some.additional.script.to.execute.js"></script>
</body>
</html>

2) Instead of return PartialView(...) you can now do return View("MyView", "PopupMaster", myModel);

2)您现在可以返回View(“MyView”,“PopupMaster”,myModel),而不是返回PartialView(...);

This will result in a partialview-like result, but with possibility to provide extra css and scripts

这将导致类似部分视图的结果,但有可能提供额外的css和脚本