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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:57:55+00:00 2026-05-26T08:57:55+00:00

I have one text field where user can write short message (like status on

  • 0

I have one text field where user can write short message (like status on g+ or fb) bellow that field I have a list where that messages need to be displayed. When user submit that message it is stored in database, after that I refresh whole View. This is how I display that list:

@foreach (var m in @Model.Messages){
   <div>
      <p>@m.Author</p>
      <p>@m.Text</p>
   </div>
}

Now I wan’t to make better user experience. I wan’t to add that message without refreshing while View. I know that I have to use JQuery, Ajax etc. but I have searched on the google and can’t find any good tutorial or example for ASP MVC / Razor and this like feature. Can somebody give me some direction?

  • 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-26T08:57:55+00:00Added an answer on May 26, 2026 at 8:57 am

    Typing asp.net mvc ajax jquery in google usually yields sufficiently enough results. But anyway here’s what you could do. Assuming you have a text field where the users will type their messages:

    @using (Html.BeginForm("AddMessage", "Messages", FormMethod.Post, new { id = "addMessageForm" }))
    {
        @Html.TextBoxFor(x => x.Author)
        @Html.TextAreaFor(x => x.Text)
        <button type="submit">Add message</button>
    }
    

    you could AJAXify this form:

    $(function() {
        $('addMessageForm').submit(function() {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function(result) {
                    $('#messages').append(result);
                }
            });
            return false;
        });
    });
    

    and finally you would have a controller action which will perform the actual adding of the message to the database:

    [HttpPost]
    public ActionResult AddMessage(MessageViewModel message)
    {
        // TODO: add the message to the database
        return PartialView("~/Views/Messages/DisplayTemplates/MessageViewModel.cshtml", model);
    }
    

    and a corresponding display template (~/Views/Messages/DisplayTemplates/MessageViewModel.cshtml):

    @model MessageViewModel
    <div>
        @Html.DisplayFor(x => x.Author)
        @Html.DisplayFor(x => x.Text)
    </div>
    

    and the list of messages will be shown using display templates and not using loops:

    <div id="messages">
        @Html.DisplayFor(x => x.Messages)
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The idea here is that the user can only have one selection for an
i have one text area <textarea name=message id=message class=text_field style=height:200px; width:500px></textarea> if i type
In one of the ms-access table I work with we have a text field
I have an input field which has a placeholder text. I want one word
I have one text input and one button (see below). How can I use
i have one domain link text i want to know that does google crawl
Running on Rails 3.1 RC1 and following this . A user can have one
i am building one module wherein user can post their data. i have few
I have one form with several text fields and one button. When i enter
I have one text box and i have to show minimum date of the

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.