Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3986186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:58:53+00:00 2026-05-20T05:58:53+00:00

Can I reduce this razor code? <li> @{ if (@Model.PublicationDate.HasValue) { @Model.PublicationDate.Value.ToString(D, new System.Globalization.CultureInfo(fr-FR))

  • 0

Can I reduce this razor code?

    <li>
    @{
        if (@Model.PublicationDate.HasValue) {
            @Model.PublicationDate.Value.ToString("D", new System.Globalization.CultureInfo("fr-FR")) 
        }
        else {
            @:"pas disponible"
        }
    }
    </li>

I was trying this but it doesn’t work:

@{(@Model.PublicationDate.HasValue) ? (@Model.PublicationDate.Value.ToString("D")) : (@:"pas disponible")}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:58:53+00:00Added an answer on May 20, 2026 at 5:58 am

    You could decorate your view model property with the [DisplayFormat] attribute:

    [DisplayFormat(DataFormatString = "{0:D}", NullDisplayText = "pas disponible")]
    public DateTime? PublicationDate { get; set; }
    

    and then your view simply becomes:

    <li>
        @Html.DisplayFor(x => x.PublicationDate)
    </li>
    

    So now it is reduced to a single and elegant line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stuck on how I can reduce this code duplication, I'm using the TextToSpeech
Hey all, how can I reduce this: www.example.com/index.php?page=viewblog&category=awesome down to this: www.example.com/blog/awesome The above
I am using a razor template so I can reduce the amount of clutter
I have written a code which can reduce the grammatical boundaries for a text,
I want to develop a web application in Silverlight. Can this reduce my web
How can I do this with generics? In my current code, I am writing
I'm trying to write out a piece of code that can reduce the LENGTH
You can reduce the number of HTTP requests to speed up your site, such
Can I reduce the textbox width without using classes? <input type=text maxlength=5 style=3px/>
Simple question :) How can I reduce build time using a parallel build /

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.