简体   繁体   中英

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.

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.

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...

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

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

<!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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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