_Layout resx file

JStus 41 Reputation points
2022-09-30T18:53:07.097+00:00

I have simple MVC app
In my _layout I would like to display

@azzedinehtmlsql .ActionLink( SomeValue, "Index", "Home")

where some value will display text in specified language(possibly from model file). So I learned how to use .resx files for different languages, but how can I use it in Layout file?

Let's say I have a model file that has

[Display(Name="SomeValue", ResourceType = typeof(Company))]
public string SomeValue{get;set;}

and I have to Company files Company.resx and Company.Fr.resx

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,306 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 26,361 Reputation points Microsoft Vendor
    2022-10-03T03:03:41.627+00:00

    Hi @JStus ,
    First you need to put Company.resx and Company.Fr.resx in the Resources folder, then add the reference of the Resource project to the Web project.
    246806-image.png

    In _Layout.cshtml, add a using statement at the top of the page:

    @using mvcdemo1.Resources  
    

    Then replace the string that needs to be replaced:

       @Html.ActionLink(Company.SomeValue, "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })  
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful