A2Zmenu Forum
»
Ask Question
»
Web Development
»
MVC
»
ASP .Net MVC DisplayFormat NullDisplayText styling Not Working
Rank: Newbie
Groups: Editors, Registered, Administrators, Moderator Joined: 5/6/2013(UTC) Posts: 3  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.
|
|
|
|
|
|
Rank: Newbie
Groups: Editors, Registered, Administrators, Moderator Joined: 5/6/2013(UTC) Posts: 3  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>
:)
|
|
|
|
A2Zmenu Forum
»
Ask Question
»
Web Development
»
MVC
»
ASP .Net MVC DisplayFormat NullDisplayText styling Not Working
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.