.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

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript