locked
Model in MVC RRS feed

  • Question

  • User52625461 posted

    Hello All,

    I have written custom attribute for DisplayName as follows

    namespace CRM.Model
    {
        public class LocalizedDisplayNameAttribute : DisplayNameAttribute
        {
            private readonly string resourcekey;
            
            public LocalizedDisplayNameAttribute(string resourceId)
                : base(GetMessageFromResource(resourceId))
            { 
            
            }
    
            public static string GetMessageFromResource(string resourceId)
            {
                // My Localization logic
                  return LocalizationResourceProvider.Current.GetString(resourceId);
            }
    
           
        }
    }
    

    When model is loaded/initiated for the first time the above custom attribute class is called successfully.

    But if, I will post back the page then, it doesn't get called.

    For example when I change my language from English to French. it still displays the English content.

    Why it is so ? How can I solve this issue ? Can we load the Model data explicitly

    Thursday, October 16, 2014 8:57 AM

Answers

  • User-1336211562 posted

    Hi Rohit,<!--?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" /--><o:p></o:p>

    <o:p></o:p>

    When model is loaded/initiated for the first time the above custom attribute class is called successfully.<o:p></o:p>

    But if, I will post back the page then, it doesn't get called.<o:p></o:p>

    For example when I change my language from English to French. it still displays the English content.<o:p></o:p>

    Why it is so ? How can I solve this issue ? Can we load the Model data explicitly<o:p></o:p>

    <o:p></o:p>

    From your description, I'm not very sure about your issue. And, I also not sure about the meaning of load the Model data explicitly. According to your code, I suppose the DisplayNameAttribute is used to get the display name. But, I don't know why it is related to change language? <o:p></o:p>

    So, I suppose perhaps you want to achieve change language function in your MVC application. If that is the case, I would like to suggest you set a break point to check your code to see if there is anything breaking.<o:p></o:p>

    Here is a thread about change language in MVC Application, you could refer to it.<o:p></o:p>

    http://forums.asp.net/t/1723919.aspx?How+can+I+change+language+of+my+MVC+3+Application<o:p></o:p>

    Best Regards,
    Luther

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 17, 2014 6:27 AM