简体   繁体   English

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

[英]Render correct partial view with ajax call

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: 雷肯宁根的景色看起来像这样:

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添加到“部分视图” ...

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 ). 1)在Views\\Shared文件夹中创建一个新的母版页cshtml(例如PopupMaster.cshtml )。 It holds a very basic HTML template: 它拥有一个非常基本的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)现在不用return PartialView(...)而是可以return View("MyView", "PopupMaster", myModel);

This will result in a partialview-like result, but with possibility to provide extra css and scripts 这将导致类似于partialview的结果,但有可能提供额外的css和脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM