Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an MVC model in which most of the field names are single-letter strings because my client's desired column headers are sentences of up to about 15 words in length. In the database, I kept the field names small so I could add calculated fields (the data is all small integer values). I kind of carried the one and two letter field names over from Excel to SQL Server, as Excel was the original 'database'.

As you can see below, I've added the DataAnnotations namespace and am using the Display directive to change the field names displayed in the MVC views, exactly as I have seen done in training videos. I'm showing two fields below, but actually, there are many such fields, as well as many such tables. Unlike in the training video where everything always works perfectly, the single-letter field names following 'Display(' are each giving me an error that says "The best overload for 'DisplayAttribute' does not have a parameter named 'G'". It says 'H' for the second one and so on.

What is causing this error? How can I get this error, marked on each field name after 'Display(', to go away? I have 21 different tables like this. I hope I don't have to revamp the entire database with super long field names. Thanks for your help.

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace MyProject.Models
{
[MetadataType(typeof(hraInMetaData))]
public partial class hraIn
{
}

public class hraInMetaData
{
[Display(G: "Long Field Name 1")]
public Nullable<byte> G { get; set; }

[Display(H: "Long Field Name 2")]
public Nullable<byte> H { get; set; }
.
.
.
.
Posted
Updated 14-Nov-16 5:41am
Comments
Philippe Mori 14-Nov-16 15:04pm    
Where have you seen code with G:? It look like you invented your own syntax which is not supported by the compiler.

1 solution

Try adding your data annotation like this: [Display(Name="G")]
 
Share this answer
 
Comments
Member 12824529 22-Dec-16 15:29pm    
Your solution worked. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900