0

I have ASP.NET 5 Web Api and need to do the following task:

Add endpoint, which get cshtml page and return generated html, so it should do the same what is does razor view engine.

What is better way to do this?

I added these views in this web api project and I think I can just make httpget request to view to get html response. Is it correct way?

So actually I need to covert ViewResult to ContentResult.

6
  • havent tested but surely you just add an mvc controller and return a view as normal? Commented Jul 18, 2021 at 17:38
  • @Ewan, I don't need to show view, just return html as string. Commented Jul 18, 2021 at 17:42
  • 2
    thats what webpages do Commented Jul 18, 2021 at 17:48
  • @Ewan, maybe you're right. Than I just need to replace services.AddControllers() to services.AddControllersWithViews() and create endpoint that returns this view. Commented Jul 18, 2021 at 17:59
  • 1
    if you want to return the string as an escaped json object then you can call the razor engine in code codemag.com/article/1312081/… Commented Jul 18, 2021 at 18:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.