.NET Core 2.2 Render cshtml as stringWhat is the difference between String and string in C#?How do I get the path of the assembly the code is in?How to escape braces (curly brackets) in a format string in .NETCase insensitive 'Contains(string)'How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Easiest way to split a string on newlines in .NET?JavaScriptSerializer - JSON serialization of enum as string.NET Core: ViewModel attributes are not renderedAsp.net custom razor view engine specify cshtml file location

Tips for remembering the order of parameters for ln?

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Cemented carbide swords - worth it?

Amiga 500 OCS/ECS vs Mega Drive VDP

Who are the people reviewing far more papers than they're submitting for review?

When would open interest equal trading volume?

Paradox regarding phase transitions in relativistic systems

With a 500GB SSD and a 250GB SSD is it possible to mirror a 250GB partition on the 500GB with the 250GB SSD using ZFS?

What the did the controller say during my approach to land (audio clip)?

Is Zack Morris's 'time stop' ability in "Saved By the Bell" a supernatural ability?

Is there an in-universe reason Harry says this or is this simply a Rowling mistake?

Can Brexit be undone in an emergency?

How do you determine which representation of a function to use for Newton's method?

How do rulers get rich from war?

Output Distinct Factor Cuboids

Lumens specs when buying a flashlight/torch. Why maglite has only 680lm but cheap ones have 900,000?

Is Yang not precluded from conducting his "UBI experiment" as an electoral candidate?

How can I check that parent has more than 1 child?

Can a business put a specific cancel-by date into a contract?

Applications of mathematics in clinical setting

Compare FEM mesh with the mesh created within Mathematica

Can't make parabola without including the tip

removing rows containing NA in every column

How is underwater propagation of sound possible?



.NET Core 2.2 Render cshtml as string


What is the difference between String and string in C#?How do I get the path of the assembly the code is in?How to escape braces (curly brackets) in a format string in .NETCase insensitive 'Contains(string)'How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Easiest way to split a string on newlines in .NET?JavaScriptSerializer - JSON serialization of enum as string.NET Core: ViewModel attributes are not renderedAsp.net custom razor view engine specify cshtml file location






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have this cshtml file located in this path



"~/Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml"


I am trying to render this as a string and pass a viewmodel to it.



Currently I am using RazorLight v1.1.0 from Nuget and this is what I have tried so far:



var tempatePath = "~/Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml";
IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);


However when I run it, I get an error saying that I require an absolute path instead. How can I convert what I have currently to an absolute path? If I give it an absolute path, when I compile and run the program, won't the absolute path disappear?










share|improve this question
































    1















    I have this cshtml file located in this path



    "~/Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml"


    I am trying to render this as a string and pass a viewmodel to it.



    Currently I am using RazorLight v1.1.0 from Nuget and this is what I have tried so far:



    var tempatePath = "~/Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml";
    IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);


    However when I run it, I get an error saying that I require an absolute path instead. How can I convert what I have currently to an absolute path? If I give it an absolute path, when I compile and run the program, won't the absolute path disappear?










    share|improve this question




























      1












      1








      1








      I have this cshtml file located in this path



      "~/Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml"


      I am trying to render this as a string and pass a viewmodel to it.



      Currently I am using RazorLight v1.1.0 from Nuget and this is what I have tried so far:



      var tempatePath = "~/Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml";
      IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);


      However when I run it, I get an error saying that I require an absolute path instead. How can I convert what I have currently to an absolute path? If I give it an absolute path, when I compile and run the program, won't the absolute path disappear?










      share|improve this question
















      I have this cshtml file located in this path



      "~/Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml"


      I am trying to render this as a string and pass a viewmodel to it.



      Currently I am using RazorLight v1.1.0 from Nuget and this is what I have tried so far:



      var tempatePath = "~/Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml";
      IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);


      However when I run it, I get an error saying that I require an absolute path instead. How can I convert what I have currently to an absolute path? If I give it an absolute path, when I compile and run the program, won't the absolute path disappear?







      c# asp.net-core razor asp.net-core-mvc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 29 at 5:43









      ArunPratap

      2,2713 gold badges11 silver badges30 bronze badges




      2,2713 gold badges11 silver badges30 bronze badges










      asked Mar 28 at 13:53









      JianYAJianYA

      57513 silver badges48 bronze badges




      57513 silver badges48 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1
















          Inject IHostingEnvironment and use _env.ContentRootPath:



          public class FooController : Controller

          private readonly IHostingEnvironment _env;

          public FooController(IHostingEnvironment env)

          _env = env;


          public IActionResult FooAction()

          var tempatePath = Path.Combine(_env.ContentRootPath, "Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml");
          IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);

          ...







          share|improve this answer

























          • Hi! Thanks for answering. Does it work when i publish the application as well? That is what I'm worried about

            – JianYA
            Mar 28 at 14:19











          • Yes. That's the entire point.

            – Chris Pratt
            Mar 28 at 15:55










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399324%2fnet-core-2-2-render-cshtml-as-string%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1
















          Inject IHostingEnvironment and use _env.ContentRootPath:



          public class FooController : Controller

          private readonly IHostingEnvironment _env;

          public FooController(IHostingEnvironment env)

          _env = env;


          public IActionResult FooAction()

          var tempatePath = Path.Combine(_env.ContentRootPath, "Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml");
          IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);

          ...







          share|improve this answer

























          • Hi! Thanks for answering. Does it work when i publish the application as well? That is what I'm worried about

            – JianYA
            Mar 28 at 14:19











          • Yes. That's the entire point.

            – Chris Pratt
            Mar 28 at 15:55















          1
















          Inject IHostingEnvironment and use _env.ContentRootPath:



          public class FooController : Controller

          private readonly IHostingEnvironment _env;

          public FooController(IHostingEnvironment env)

          _env = env;


          public IActionResult FooAction()

          var tempatePath = Path.Combine(_env.ContentRootPath, "Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml");
          IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);

          ...







          share|improve this answer

























          • Hi! Thanks for answering. Does it work when i publish the application as well? That is what I'm worried about

            – JianYA
            Mar 28 at 14:19











          • Yes. That's the entire point.

            – Chris Pratt
            Mar 28 at 15:55













          1














          1










          1









          Inject IHostingEnvironment and use _env.ContentRootPath:



          public class FooController : Controller

          private readonly IHostingEnvironment _env;

          public FooController(IHostingEnvironment env)

          _env = env;


          public IActionResult FooAction()

          var tempatePath = Path.Combine(_env.ContentRootPath, "Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml");
          IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);

          ...







          share|improve this answer













          Inject IHostingEnvironment and use _env.ContentRootPath:



          public class FooController : Controller

          private readonly IHostingEnvironment _env;

          public FooController(IHostingEnvironment env)

          _env = env;


          public IActionResult FooAction()

          var tempatePath = Path.Combine(_env.ContentRootPath, "Areas/Services/Views/Quotations/SpecificForms/PC/PCReceipts.cshtml");
          IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);

          ...








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 28 at 14:04









          Chris PrattChris Pratt

          174k23 gold badges259 silver badges326 bronze badges




          174k23 gold badges259 silver badges326 bronze badges















          • Hi! Thanks for answering. Does it work when i publish the application as well? That is what I'm worried about

            – JianYA
            Mar 28 at 14:19











          • Yes. That's the entire point.

            – Chris Pratt
            Mar 28 at 15:55

















          • Hi! Thanks for answering. Does it work when i publish the application as well? That is what I'm worried about

            – JianYA
            Mar 28 at 14:19











          • Yes. That's the entire point.

            – Chris Pratt
            Mar 28 at 15:55
















          Hi! Thanks for answering. Does it work when i publish the application as well? That is what I'm worried about

          – JianYA
          Mar 28 at 14:19





          Hi! Thanks for answering. Does it work when i publish the application as well? That is what I'm worried about

          – JianYA
          Mar 28 at 14:19













          Yes. That's the entire point.

          – Chris Pratt
          Mar 28 at 15:55





          Yes. That's the entire point.

          – Chris Pratt
          Mar 28 at 15:55








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399324%2fnet-core-2-2-render-cshtml-as-string%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현