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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:56:59+00:00 2026-06-19T00:56:59+00:00

I need to display a message in the view from the controller . Here’s

  • 0

I need to display a message in the view from the controller. Here’s my code;

VIEW

@Html.LabelFor // How do i write the rest to display the message

CONTROLLER

public ActionResult Index(MyModel model)
    {

        // I Need to send a String to the Label in the View

        return View();
}
  • 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-19T00:57:01+00:00Added an answer on June 19, 2026 at 12:57 am

    Arguably the more elegant solution, when called for at least, is to use a strongly-typed view (with a model – the M in MVC). A simple example could be:

    The model:

    public class MessageViewModel
    {
        public string Message {get; set;}
    }
    

    The controller:

    public ActionResult Index()
    {
        var viewModel = new MessageViewModel {Message = "Hello from far away"};
        return View(viewModel);
    }
    

    The view:

    @model MyNamespace.MessageViewModel
    
    <h2>@Html.DisplayFor(model => model.Message)</h2>
    

    Would I bother with this for a single message on a page? Surprisingly, most of the time I would. There’s something elegant about the view knowing exactly what to expect (and vice versa), Intellisense support, and the HtmlHelper‘s DisplayFor() method where you can do all kinds of implicit formatting.


    That being said, the “simplest” (read: quick and dirty, but gets ugly quick) solution would be to stuff your message into the ViewBag dynamic object.

    In the controller:

    ViewBag.MyMessage = "Hello from a far away place";
    

    In the view:

    @ViewBag.MyMessage
    

    But doing this, you lose Intellisense, repeatability (DRY), and possibly your sanity. One property used in one place, maybe (a la ViewBag.Title that the default _Layout page uses). A whole bunch of disconnected objects stuffed in the bag, no thank you.

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

Sidebar

Related Questions

I have the following view that i need to display an error message when
i am developing one application with map view i need display the weather depends
I need to display the parent from the first Element of input.xml Also I
I need to display a certain view when an activity starts, and when the
I need to display array of images in a single view which have various
In my MVC application I need to display a certain message if the user
I need to display a message to the user. However, it is quite a
I have a view (skipping redundant code for simplicity): @model CompetencyModel @using (Html.BeginForm()) {
I have a little exercise where I need to access data from a view
This is my json response from server, {class:co.myapp.json.WsResponse,code:0,message:SUCCESS, packet: {class:co.myapp.json.MyWantPacket,fullname:Viswa,imageURI:images/1.png,userid:1,username:viswa11,wantSuggestion:learn guitar, wants:[{ class :

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.