Loading
logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

saupadhy
#1 Posted : Sunday, December 22, 2013 7:26:31 PM(UTC)
saupadhy

Rank: Newbie

Groups: Editors, Registered, Administrators, Moderator
Joined: 5/6/2013(UTC)
Posts: 3
India
Location: Hyderabad

Hi Experts,

I have a Scenario where I want to display say "anonymous" text for Reviewer name whenever the user forget to enter the reviewer name field.
I some where saw that it can be easily done in ASP.NET MVC by adding DisplayFormat Attribute to the Property in Model.

Model:
[Display(Name = "Reviewer Name")]
[DisplayFormat(NullDisplayText = "Anonymous")]
[MaxLength(10)]
public string ReviewerName { get; set; }

View:
<div>
@item.ReviewerName
</div>

But when I run the code I see blank, not the word anonymous. Any idea what I am missing.
Sponsor
saupadhy
#2 Posted : Monday, December 23, 2013 12:00:53 AM(UTC)
saupadhy

Rank: Newbie

Groups: Editors, Registered, Administrators, Moderator
Joined: 5/6/2013(UTC)
Posts: 3
India
Location: Hyderabad

Some digging and I got the answer...

Actually in order to render the DisplayTemaplate we need to use the the helper method Display for.

So in order to achieve I am try to do

instead of
<div>
@item.ReviewerName
</div>

we should we
<div>
@Html.DisplayFor(model => model.ReviewerName)
</div>

:)
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF | YAF © 2003-2018, Yet Another Forum.NET
This page was generated in 0.329 seconds.