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 8862937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:51:03+00:00 2026-06-14T15:51:03+00:00

After upgrading my MVC 3 solution to MVC 4 with Razor 2 I came

  • 0

After upgrading my MVC 3 solution to MVC 4 with Razor 2 I came across the following problem.

This code in a view

@{
    string main = "archive";
}
    <div class="selected-@(main == "archive")"></div>

returns this in MVC 3

<div class="selected-True"></div>

and this in MVC 4

<div class="selected-class"></div>

which breaks my CSS.

Is that a bug introduced by the new conditional attribute feature in Razor 2?

My workaround is this:

<div class="selected-@((main == "archive").ToString())"></div>

which returns this:

<div class="selected-True"></div>

Does anyone have a better suggestion?

  • 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-06-14T15:51:04+00:00Added an answer on June 14, 2026 at 3:51 pm

    My bug-or-not question is answered here: https://stackoverflow.com/a/13455272/533460

    It’s not a bug, it’s a new feature of Razor 2!

    What is happening in my code is based on this principle

    <input checked="@ViewBag.Checked" type="checkbox"/>
    

    becomes

    <input checked="checked" type="checkbox"/>
    

    when ViewBag.Checked == true.

    So

    <div class="@(main == "archive")"></div>
    

    becomes

    <div class="class"></div>
    

    Thanks to @webdeveloper (https://stackoverflow.com/users/1667969/webdeveloper) for pointing me to the answer.

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

Sidebar

Related Questions

I encountered the following problem after upgrading to the latest version 1.8.1 of data.table
I have the following code in a c# MVC 3 razor page where I
MVC 4 Beta project fails to compile after upgrading to .Net 4.5. This happens
After upgrading to a newer hibernate version (guess it came with the switch from
After upgrading to ReSharper5 it gives me even more useful tips on code improvements.
We are getting this error after upgrading to NHibernate 2.1. [QueryException: Cannot simultaneously fetch
After upgrading from Visual Studio 2010 to 2012 code started throwing ArgumentOutOfRangeException - Index
After upgrading to the iPhone SDK 4.0, I get the following error when building
After upgrading to my ASP.NET MVC 4 Developer Preview assemblies to the latest MVC
After upgrading one of my websites to MVC 4 and upgrade all my packages

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.