Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. _ViewImports.cshtml question

_ViewImports.cshtml question

Scheduled Pinned Locked Moved .NET (Core and Framework)
questionasp-nethostingcloud
5 Posts 2 Posters 21 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • pkfoxP Offline
    pkfoxP Offline
    pkfox
    wrote on last edited by
    #1

    This question is about a net core Web app Hi all , if I put this line in _ViewImports.cshtml (where IPageSettings is in the IServiceCollection)

    @inject IPagingSettings PageSettings;

    PageSettings is available in all my views EXCEPT _layout.cshtml, anyone know why ? I can't find anything with Mr Google

    Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

    Richard DeemingR 1 Reply Last reply
    0
    • pkfoxP pkfox

      This question is about a net core Web app Hi all , if I put this line in _ViewImports.cshtml (where IPageSettings is in the IServiceCollection)

      @inject IPagingSettings PageSettings;

      PageSettings is available in all my views EXCEPT _layout.cshtml, anyone know why ? I can't find anything with Mr Google

      Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      According to the documentation[^], _ViewImports should apply to every page, including layouts and partial views, whereas _ViewStart doesn't apply to layouts or partial views. There must be something else going on. What's the hierarchy of your views folder, and what's the error message you're getting?


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      pkfoxP 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        According to the documentation[^], _ViewImports should apply to every page, including layouts and partial views, whereas _ViewStart doesn't apply to layouts or partial views. There must be something else going on. What's the hierarchy of your views folder, and what's the error message you're getting?


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        pkfoxP Offline
        pkfoxP Offline
        pkfox
        wrote on last edited by
        #3

        It's the standard hierarchy Richard - _ViewImports.cshtml is in the root Views folder - there is no error it's (the var) not available when I try and use it with @PageSettings, in all the other views I get intellisense Edit I should mention that, if I put the same @inject statement directly in _layout.cshtml it works

        Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

        Richard DeemingR 1 Reply Last reply
        0
        • pkfoxP pkfox

          It's the standard hierarchy Richard - _ViewImports.cshtml is in the root Views folder - there is no error it's (the var) not available when I try and use it with @PageSettings, in all the other views I get intellisense Edit I should mention that, if I put the same @inject statement directly in _layout.cshtml it works

          Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          "Not available" as in "not listed by intellisense", or does it not compile if you try to use it?


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          pkfoxP 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            "Not available" as in "not listed by intellisense", or does it not compile if you try to use it?


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            pkfoxP Offline
            pkfoxP Offline
            pkfox
            wrote on last edited by
            #5

            Good call Richard it does actually work but I don't like red squigglies - I've noticed the same with the using statements, same thing intellisense works in all views except _layout where I'm prompted to add the full namespace.class

            Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups