Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is how I did it:</p> <ol> <li><p>Created new Attribute as follows:</p> <pre><code>public class HelpPromptAttribute : Attribute { public HelpPromptAttribute(string text) { myproperty = text; } protected string myproperty; public string HelpTextKey { get { return myproperty; } set { myproperty = value; } } } </code></pre></li> <li><p>Added attribute to entity property as follows:</p> <pre><code>[HelpPrompt("ProjectDescription")] [Required(ErrorMessageResourceName = "ProjectDescriptionRequired", ErrorMessageResourceType = typeof(EntityValidationMessages))] [StringLength(50, ErrorMessageResourceName = "ProjectDescriptionTooLong", ErrorMessageResourceType = typeof(EntityValidationMessages))] public string ProjectDescription { get; set; } </code></pre></li> <li><p>Added Extension Method to Entities as follows:</p> <pre><code>public static class EntityBOExtensions { public static string PropertyHelp(this object objectBO, string PropertyName) { Type type = objectBO.GetType(); foreach (PropertyInfo pInfo in type.GetProperties()) { if (string.Compare(pInfo.Name, PropertyName) == 0) { foreach (Attribute attr in Attribute.GetCustomAttributes(pInfo)) { if (attr.GetType() == typeof(HelpPromptAttribute)) { string key = ((HelpPromptAttribute)attr).HelpTextKey; if (!string.IsNullOrEmpty(key)) return EntityBOHelp.ResourceManager.GetString(key); } } } } return null; } } </code></pre></li> <li><p>Added a HtmlHelper (simple) as follows:</p> <pre><code>public static string LocalisedTextBoxWithHelp(this HtmlHelper helper, string name, object value, string helptext) { string textbox = helper.TextBox(name, value, new { helpprompt = helptext }); return textbox; } </code></pre></li> <li><p>And finally used the folowing markup in the View:</p> <pre><code> &lt;%= Html.LocalisedTextBoxWithHelp("project.ProjectDescription", Model.ProjectDescription, Model.PropertyHelp("ProjectDescription"))%&gt; </code></pre></li> </ol> <p>This does the job although it needs refinement. ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload