ASP.NET Core has the new View Components feature . Viewing components consist of two parts, a class and a result (usually this is a kind of razor). View components are not directly accessible as an HTTP endpoint; they are called from your code (usually in the form). They can also be called from the controller that best suits your needs. Create a razor view to report success
<h3> Success Message <h3> Your Success Message...
Create the appropriate view component
public class SuccessViewComponent : ViewComponent { public async Task<IViewComponentResult> InvokeAsync() { return View(); } }
Please note that the name of the view and the name of the component and path for these files follow a standard very similar to the controller and views. Refer to the basic ASP.NET documentation for the same.
Call a view component from your action method
public IActionResult DoSomething() { bool success=someWork(); if(success) { return ViewComponent("Success"); } else { return View(); } }
source share