Create a controller and an Action

In your Class Library project you can create a Controller and the corresponding Action.

namespace EV5.Samples.Embedded.Controllers
{
    public class SamplesController : Controller
    {
 
        public ActionResult RetrieveHtmlResult()
        {
            return new EmbeddedHtmlStringResult("EV5.Samples.Embedded.Assets.LandingPage.index2.html"this.GetType().Assembly);
        }
 
        public ActionResult RetrieveSimpleRazor()
        {
 
            return View("/EV5.Samples.Embedded/Views/Sample/index.cshtml");
 
        }
    }
 
}
We're going to return an ActionResult here that contains the html for the Landing Page, but first we need to prepare the web applicaiton to be able to find this controller, and the landing page html to referr to the embedded file system for resoures.

Register your controller in your Web application

To register the new controller in your web project to a particular route use the following code in the CConfigureServices method of the Startup class:

services.AddControllers().PartManager.ApplicationParts.Add(new AssemblyPart(typeof(SamplesEmbeddedPlugin).Assembly));

Change links in the Landing page to point to the Embedded File system

You need to modify the asset reference links in the Index.html of the Landing Page to refer to the Embedded File system.

<!-- Favicon-->
   <link rel="icon" type="image/x-icon" href="/EV5.Samples-Assets.LandingPage.assets.favicon.ico" /> <!--<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />-->
<link href="/EV5.Samples-Assets.LandingPage.css.styles.css" rel="stylesheet" />    <!--<link href="css/styles.css" rel="stylesheet" />-->
<img src="/EV5.Samples-Assets.LandingPage.assets.img.navbar-logo.svg" alt="..." /> <!--<img src="assets/img/navbar-logo.svg" alt="..." />-->
Etc... the same way for all referenced resources

Use EmbeddedHtmlStringResult in your action

In order to retrieve an embedded html as an ActionResult use the EmbeddedHtmlResult class. You have to pass the Assembly or the FullName of the Assembly that contains the html, and the resource name that refers to the html.

public ActionResult RetrieveHtmlResult()
        {
            return new EmbeddedHtmlStringResult("EVE.Mvc.Samples.Embedded.Assets.LandingPage.index2.html"this.GetType().Assembly);
        }
The following link will invoke this controller action: /Samples/RetrieveHtmlResult