1

Html.DisplayFor stopped displaying the display name and the formatted string... My code is bellow ... any ideas? i have searched around any couldn't find anything. thanks

[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
[Display(Name = "Date")]
public DateTime EventDateTimeDay { get; set; }

[Display(Name = "Seconds")]
[DisplayFormat(DataFormatString = "{0:0.00} s")]
public double Duration { get; set; }

Razor .cshtml:

@model IEnumerable<OurClass>
...
        <th>
            @Html.DisplayNameFor(model => model.EventDateTimeDay)
        </th>

...
    @foreach (var item in Model)
    {
...
            <td>
            @Html.DisplayFor(modelItem => item.EventDateTimeDay)
            </td>

2 Answers 2

0

You should try using the DisplayName attribute

    [DisplayName("Seconds")]
    public double Duration { get; set; }
Sign up to request clarification or add additional context in comments.

2 Comments

yes tried that too, that does not work. thanks for responding tho. and it doesn't explain why the DisplayFormat doesn't work.
Looks like this has been answered in another post [link]stackoverflow.com/questions/15976576/…
0

Figured out the problem. Am using Unity as an IOC and to reduce unity resolve errors I added this in the UnityConfig:

container.RegisterType<ModelMetadataProvider, EmptyModelMetadataProvider>();

which wiped out the data attributes. changed it to this and it worked fine:

container.RegisterInstance<ModelMetadataProvider>(ModelMetadataProviders.Current);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.