Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DisplayNameFor tag change text

I have following code in my Details View of Entity A

<dt>
    @Html.DisplayNameFor(model => model.User1.UserName)
</dt>
<dd>
    @Html.DisplayFor(model => model.User1.UserName)
</dd>

I want to change their title that is shown in Details View it is showing UserName where i want it to be Submitted by it cant be overloaded because DisplayName For donot have any overloaded function with two params @Html.DisplayFor(model => model.User1.UserName,"Submitted By") Not working any Help

Here is my Model of Bugs Where i have Fields of Assigned to and submitted by which are related to the users model so i am having problem that "UserName" is shown at the place of column Name where it should show the Names as "Assigned To" and "Submitted By"

    public partial class Bug
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string Priority { get; set; }
    public string Severity { get; set; }
    public string Status { get; set; }
    public int AssignedTo { get; set; }
    public int SubmittedBy { get; set; }
    public int ComponentID { get; set; }
    public int ProjectID { get; set; }
    public System.DateTime DueDate { get; set; }
    public Nullable<int> BugNumber { get; set; }
    public string NormalFlow { get; set; }
    public System.DateTime CreationDate { get; set; }

    public virtual Component Component { get; set; }
    public virtual Project Project { get; set; }
    public virtual User User { get; set; }
    public virtual User User1 { get; set; }
}
like image 224
Hasan Mir Avatar asked Aug 01 '16 21:08

Hasan Mir


1 Answers

You can control the displayed text via the [Display] attribute on your model. In your case you'd want to set the attribute on the underlying model for User1:

public class User
{
   [Display(Name = "Submitted By")]
   public string UserName;
}

See https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute.name%28v=vs.110%29.aspx for more details on the DisplayAttribute class.

like image 156
Dean Goodman Avatar answered Oct 05 '22 23:10

Dean Goodman