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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:19:04+00:00 2026-06-05T12:19:04+00:00

This sounds really basic yet I couldn’t find the answer. I pass a Message

  • 0

This sounds really basic yet I couldn’t find the answer.

I pass a Message struct to the View and I want to display it.

If the Message.Category field is “Technical” I want to display “Technical Problem” else just display it as it is.

How do I make the view understand that Technical Problem isn’t a statement but html text I want to display?

My code:

<span class="cright" id="cat">
@{
    if (String.Compare(ViewBag.Message.Category, "Technical") == 0) 
    {
     Technical Problem <----THIS  
    } 
    else @ViewBag.Message.Category
 }
</span>

More info:
I’m working on a messaging system. Users create a message and as it is being sent they can view it. The category is compulsory (Question, Suggestion or Technical Problem) and to avoid redundancy in the database I truncate the last option to just ‘Technical’, however when the users view their sent message I want it to show up in full.

Thanks everyone; from all your answers I arrived at:

<span class="cright" id="cat">

      @if (ViewBag.Message.Category == "Technical ")
         {<text>Technical Problem</text>}
       else
         {<text>@ViewBag.Message.Category</text>}

</span>

which works just as I wanted.

  • 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-05T12:19:06+00:00Added an answer on June 5, 2026 at 12:19 pm

    Original Answer

    if(ViewBag.Message.Category == "Technical")
    {
      <span>Technical problem</span>
    }
    else
    {
      <span>Problem is : @(ViewBag.Message.Category)</span>
    }
    

    Updated Answer

      //Model
       public class Message
       {
          public int ID {get; set;}
          public string Message {get; set;}
          public string Category {get; set;}
       }
    
       //Controller
        public ActionResult Index()
        {
          //If you use Linq to Sql, I made this up but this should give you an idea
    
          using(MessageDataContext context = new MessageDataContext())
          {
            var messages = context.Messages.Where(m => m.Category == "Technical")
           .Select(m => new Message { ID = m.ID, Message = m.Text, Category = m.Category});
    
            return View(messages);
          }
        }
    
    //View
    @model IEnumerable<Message>
    
    @foreach(var message in Model)
    {
        if(message.Category == "Technical")
        {
          //Id and class will be "TechnicalMessage1"
          //Now you can create css class called "TechnicalMessage1" and only message with Id = 1 will have it
          <span id="@(message.Category)Message@(message.ID)" class="@(message.Category)Message@(message.ID)">Technical problem</span>
        }
        else
        {
          <span>Problem is : @(ViewBag.Message.Category)</span>
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This sounds like a really basic question. Let's say I have the following Form
This sounds really simple and for the life of me I can not find
This sounds like a really simple question, but I am new to PHP. If
This question might be closed as it sounds vague but I'm really asking this
I'm fairly new to directx so this may sound really basic. I have started
This might sound very very basic 101 type question, but I really need help
This sounds really stupid, but I was told that you could drag-and-drop visual components
This sounds really simple but it's like an onion - lots of layers as
Sorry if this sounds stupid but I'm really new to LiftWeb and just struggling
This sounds like a trivia question but I really need to know. If you

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.