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

  • Home
  • SEARCH
  • 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 7665711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:38:40+00:00 2026-05-31T14:38:40+00:00

All, I am very new to MVC3 / jQuery combo and have been reading

  • 0

All,

I am very new to MVC3 / jQuery combo and have been reading tutorials. While I kind of get the concept, razor syntax etc. I’m still a bit confused on how to implement a basic concept that I’m trying to.

I have a textarea and when someone enters some text into it and hits enter, I want to trigger a ajax call to the server with the content of the text area, and get back a fully formed HTML blurb that I can put in a div. Now as I understand in MVC3 this would be a view, so in a sense I’m rendering a view on the server and sending it back so I can put it in HTML.

Is this possible? Any examples that I can look up to see how this done? I know how to capture keystrokes, get the value etc., it’s this partial rendering of a fully formed HTML via ajax that I’m struggling to understand.

Thanks,

  • 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-31T14:38:42+00:00Added an answer on May 31, 2026 at 2:38 pm

    You can do with jQuery. This is how it works. you listen for the keydown event of the text area and when there is a keydown, check what key it is.if it is enter key, then make a jQuery ajax post call to a server page (action method in your controller with the data).Save the data there to your tables and return the markup of what you want and return that. in your script load it to your relevant div.

    HTML

    //Load jQuery library in your page
    
    <textarea id="txtComment" > </textarea>
    <div id="divComment"></div>
    

    Javascript

    $(function(){
    
     $("#txtComment").keydown(function (event) {
    
         if (event.keyCode == 10 || event.keyCode == 13) {
    
             var comment=$("#txtComment").val();
             comment=encodeURIComponent(comment);
             $.post("yourcontroller/actionmethod?data="+comment,function(response){
             $("#divComment").html(response);
           });
    
        }
    
     });    
    
    });
    

    and your controller action method

    public ActionResult actionmethod(string data)
    {
      //Do some sanitization on the data before saving.
    
      // Call your method to save the data to your tables.
    
       CommentViewModel objCommentVM=new CommentViewModel();
       objCommentVM.Comment=data;
    
      return View("PartialCommentView",objCommentVM);
    
    }
    

    You should have a ViewMolde class called “CommentViewModel” like this

    public class CommentViewModel
    {
       public string Comment{ set; get; }
    }
    

    and you should have a View called PartialCommentView which is strongly typed to CommentViewModel

    @model FlashRack.ViewModel.RackViewModel
    @{
        Layout = null;
    }
    <div>
     @Model.Comment
    </div>
    

    If you are simply returning a string, instead of returning a View, you can simply return the string using Return Content("your string here") method as well. But i prefer returning the ViewModel via View because it is more scalable and clean approach to me.

    Your action method will return the markup you have in your PartialCommentView with the data.

    Keep in mind that you have to take care of the special characters and escaping them properly.

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

Sidebar

Related Questions

Im very new to all coding including jquery. I though this would have been
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
I'm very new with rails and I've been building a CMS application backend. All
Hi All I am very new to c# .I have searched google how to
I'm very new to web-development (I feel like all my posts lately have started
I am all very new to this and am trying to use extended hex
I am very new at all this c# Windows Phone programming, so this is
I'm very new to C++ and would really appreciate any and all help. I
All, I am very new to Windows Phone and really don't know where to
This is very fast in all browsers: var curLayer = new OpenLayers.Layer.Text(layer, { location:

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.