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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:30:48+00:00 2026-06-11T19:30:48+00:00

I am developing an MVC application with razor syntax. I am developing the partial

  • 0

I am developing an MVC application with razor syntax.

I am developing the partial class for commenting feature.

I have code in which disply output of comments in following pattern.

John Smith 15-Aug-2012 
-------------------------------
Called Customer today, hold me to call later.

Will Parkar 15-Aug-2012 
-------------------------------
Keep track with him.

*Add New Comment in below text box.*
 ___________________________________________
|Called Again...                            |
|                                           |
|___________________________________________|

 Add Comment   Clear

Now, whenever user put the comment in text box , that text should added in above list…

out put should be

John Smith 15-Aug-2012 
-------------------------------
Called Customer today, hold me to call later.

Will Parkar 15-Aug-2012 
-------------------------------
Keep track with him.


John Smith 16-Aug-2012 
-------------------------------
Called Again...    <---------------------New Comment get added here.

*Add New Comment in below text box.*
 ___________________________________________
|                                           |
|                                           |
|___________________________________________|

 Add Comment   Clear

I have below code…

    @model  IEnumerable<CRMEntities.Comment>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>


 <!DOCTYPE html>

<script src="../../Scripts/jquery.js" type="text/javascript"></script>

<script type="text/javascript">
    function clearText() 
    {
         document.getElementById('Comment').value = "";

    }
</script>



<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
 $('#AddCommentButton').click(function () {
 $.ajax({
  type:'post',
  url: '/Comment/SaveComments', //url to your action method
  dataType: 'json',
  data: { 'comments': $('#Comment').val() },
  success: function(data)
  {
      $('#ParentBlock').appendChild("<div>" + data.msg + "</div>");
  }
 });
});

</script>





<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".ShowComments").click(function () {
            $(".ParentBlock").slideToggle("slow");
            $("CommentP").append(document.getElementById('Comment').value);


        });
    });
</script>





<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">



    $(document).ready(function () {
        $(".ShowComments2").click(function () {
          $(".1").append("<strong>Hello</strong>");
        });
    });


</script>


<style type="text/css"> 
div.ParentBlock
{
position:relative;
display:none;
}

#ClassPara
{
   position:relative;
   background-color:#ECF5FC;
   cursor:pointer;
   border:2px;
   width: 115px;
   border-style:solid;
   border-width:thin;
   border-color: #DCEDF8;

}



<style type="text/css">

#OwnerName
{
    background-color : #F0F6FF;
    font-style:normal;
    font-family:Calibri;

}


#CommentTextBlock
{
     background-color : #F9F9FF;
}

#EmpName
{
   font-style:normal;
   font-size:medium;
}

#Clear
{
    text-decoration:underline;
    cursor:pointer;
    color:Blue;

}

#AddComment
{
    text-decoration:underline;
    cursor:pointer;
    color:Blue;
}



</style>



</head>
<body>

@{



    <p id="ClassPara" class="ShowComments" >Show Comments</p>


    <div class="ParentBlock">



    @foreach (var item in Model)
    {
        <div id="OwnerName">

         <span class="EmpName"> @Html.ActionLink(item.Owner.FullName, "Details", "EMployee", new { id = item.OwnerId }, new { @style = "color:#1A6690;" })</span>

           @Html.DisplayFor(ModelItem => item.CommentDateTime)

        </div>

       @* <div id="CommentTextBlock">
           @Html.DisplayFor(ModelItem => item.CommentText)
        </div>*@

        <p class="CommentP">
           @Html.DisplayFor(ModelItem => item.CommentText)
        </p>
        <br />


    }



    </div>


   @Html.TextArea("Comment", "", 5, 80, "asdsd")


    <input type="button" value="Add Comment" id="AddCommentButton"/>                         
    <input type="button" value="Clear" onclick="clearText()"/>                    

    <br />




  @*  <label id="AddComment">Add Comment</label>
    <label id="Clear" onclick="clearText()">Clear</label>*@

}


</body>
</html>

How to do this ?

  • 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-11T19:30:49+00:00Added an answer on June 11, 2026 at 7:30 pm

    On click of ADD Comment button post that comment to your action to save it to Database or wherever you want to save, and then return that comment in call back function of ajax to show it on page.

    $('#addCommentButtonID').click( function() {
     $.ajax({
      type:'post',
      url: 'SaveComments' //url to your action method
      dataType: 'json',
      data: {'comments':$('#textboxId').val()},
      success: function(data)
      {
         $('#yourMainDiv').appendChild("<div>"+data.msg+"</div>");
      }
     });
    });
    

    Second way :

    $('#addCommentButtonID').click( function() {
        $.post('SaveComments',comments:$('#commentTextbox').val(),
            function (data) {
               $('#yourMainDiv').appendChild("<div>"+data.msg+"</div>");
            },'json');
    });
    

    Your Action

    public JsonResult SaveComments(string comments)
    {
       // save it wherever you want
       // after saving success return this string as jsonresult
       return Json(new { sc = true, msg = comment });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I’m developing MVC application and I have following classes in my model: public class
I am developing MVC 3 application and using razor syntax. In this application I
I am developing MVC 3 application and using razor syntax. In this application I
I am developing MVC application and using razor syntax. In this application I am
I am developing MVC application and using razor syntax. In this application I am
I am developing MVC application and using razor syntax. In this application I am
I am developing MVC application with Razor syntax. I am trying to Slidetoggle the
I am developing MVC application and using razor syntax. In this application I am
I am developing MVC application and using razor syntax. In this application I am

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.