0

I'm trying to use elements of the boilerplate Login view in a React app.

In standard ASP.NET Core 2 Identity projects, we have

@await Html.PartialAsync("_LoginPartial")

in _Layout.html. I want to expose this content in a controller, to get the content in a React app.

The idea would be to have in the controller something like this:

public async Task<IActionResult> LoginPartialAsync()
{
    return Content(await Html.PartialAsync("_LoginPartial"));
}

However, I cannot get to know where the Html comes from (sounds to be a IHtml<dynamic>, it's not Microsoft.AspNetCore.Html).

Any idea ?

2
  • do you mean the namespace of Html class ? Commented Apr 10, 2018 at 19:29
  • It's a HtmlHelper class, see doc Commented Apr 10, 2018 at 19:31

2 Answers 2

2

You don't need the HtmlHelper, you can use the PartialView method:

public IActionResult LoginPartial()
{
    return PartialView("_LoginPartial");
}
Sign up to request clarification or add additional context in comments.

Comments

0

In the case the ASP.NET project doesn't have the directory Views but Pages which contains _LoginPartial.chtml, we need to provide:

    public IActionResult LoginPartial()
    {
        return PartialView("../../Pages/_LoginPartial");
    }

Comments

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.