Unicco
Unicco

Reputation: 2580

Change DisplayNameFor (name) using WCF and MVC

I'm running a project with a WCF-service and a MVC-client. I'd like to display proper columnnames when populating the data within the MVC view. As per default, the view is generated using @Html.DisplayNameFor(model => model.FeeAmount) - this displayed: "FeeAmount" on my View. I'd like to change this to something proper.

Using the DisplayName-attribute dosen't work on client. Here is my DataContract:

[Required]
[DataMember]
[DisplayName("Fee")]
public decimal FeeAmount { get; set; }

Using the DataMember(name = "Fee") changes the propertyname. I'd like to keep the propertyname "FeeAmount", and only change how it's being displayed.

How can I achieve this, the easiest way?

I'm using EF code first, WCF and MVC.

Upvotes: 0

Views: 216

Answers (1)

Jins Peter
Jins Peter

Reputation: 2469

Try this. use a [Display(Name ="fee")] attribute at your viewmodel

using System.ComponentModel.DataAnnotations;
[Required]
[Display(Name = "Fee")]
public decimal FeeAmount{get;set;}

and use @Html.LabelFor(model=>model.FeeAmount) in cshtml

Upvotes: 1

Related Questions