.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;
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
add a comment
|
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
add a comment
|
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
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
c# asp.net-core razor asp.net-core-mvc
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
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
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);
...
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
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
...
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
add a comment
|
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);
...
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
add a comment
|
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);
...
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);
...
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
add a comment
|
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
add a comment
|
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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