skip to Main Content

In my .NET 6.0 / C# project, I have variable defined as

{  
    "Address": {
        "AddressLine1": "220 E. Yut Drive Suite 20",
        "AddressLine2": "giuuiu, CA 85679"
    },
    "AddressLine3": "22qwewqe"
}

I need to access addressLines in 1 of the html files defined in project. I have tried below ways but none worked.

  <p class=MsoNormal>
      <span style='mso-bookmark:_Hlk45183937'>
         <i><%$ AppSettings: Address.AddressLine1 %><o:p></o:p></i> 
      </span>
      <span style='mso-bookmark:_Hlk45183937'>
          <i><%$ appsettings: AddressLine3 %><o:p></o:p></i>
      </span>
      <span style='mso-bookmark:_Hlk45183937'>
          <i><%=ConfigurationManager.AppSettings["AddressLine3"]%><o:p></o:p></i>
      </span>
      <%=ConfigurationManager.AppSettings("AddressLine3")%>
  </p>

I need to know how can I access these params inside html file

2

Answers


  1. If you you mean .cshtml, you could inject IConfiguration directly

    @inject IConfiguration configuraion
    
    @configuraion.GetSection("Address").GetSection("AddressLine1").Value
    @configuraion["Address:AddressLine1"]
    

    By the way <%$ %>is syntax for webform which is not used asp.net core 6.0.

    Login or Signup to reply.
  2. Trick it with a Route to a Controllers Get method that returns your HTML with the settings embedded.

    [HttpGet]
    [Route("hello.html")]
    public IActionResult YourHtmlFile(
    {
        string htmlContent = "<html><body><h1>Hello, world!</h1></body></html>";
        return Content(htmlContent, "text/html");
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search