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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:20:20+00:00 2026-05-24T22:20:20+00:00

This solution works, but I think it can much better be done JQuery: $(‘#addMessage’).click(function

  • 0

This solution works, but I think it can much better be done

JQuery:

$('#addMessage').click(function () {
    var textMessage = $('#ticketMessage').val();
    var isInternal = $('#isInternal')[0].checked;
    var ticketID = $('#TicketID').val();
    $.ajax({
        url: '/Ticket/AddMessage',
        type: 'POST',
        data: { textMessage: textMessage, isInternal: isInternal, ticketID: ticketID },
        success: function (data) {
            var tbody = $('#allMessages').children()[0];
            tbody.innerHTML = tbody.innerHTML + data;
            $('#ticketMessage').val("");
            $('#isInternal')[0].checked = false;
        }
    });
});

controller

  public string AddMessage(string textMessage, bool isInternal, int ticketID)
        {


     Message message = new Message();
        message.IsInternal = isInternal;
        message.TicketMessage = textMessage;
        message.TicketID = ticketID;
        DateTime created=DateTime.Now;
        message.CreatedDateTime = created;
        message.PersonID = AppSecurity.Security.GetPersonID(Session);

        var personRepository =  new PersonRepository(_context);
        MessageRepository messageRepository = new MessageRepository(_context);
        messageRepository.Add(message);
        _context.SaveChanges();

        string relSrc = (personRepository.GetById((int)message.PersonID) as Employee).Image;
        string source = "";
        string isInternalStr = "";
        if (message.IsInternal) 
            isInternalStr = "Internal";
        if (message.Person is Employee) { source = relSrc != null ? "../../Images/TicketFiles" + relSrc.Replace('\\', '/') : "../../Images/TicketFiles/Employees/no-profile.png"; }
        String response = "<tr><td style=\"width: 25%\" valign=\"top\"><table><tr>" 
            + "<td><img src=\""+source+"\" alt=\"\" style=\"height: 60px\"/></td>" 
            + "</tr><tr><td>" 
            + AppSecurity.Security.GetUserFullName(Session)
            + "</td></tr><tr><td>"
            + created.ToString("dd.MM.yyyy") + " - " + created.ToString("HH:mm:ss")
            + "</td></tr></table></td><td style=\"width: 75%; padding:0px;\" valign=\"top\"><table style=\"width: 100%; height: 130px\" cellspacing=\"0\" cellpadding=\"0\">"
            + "<tr><td style=\"height: 20px; padding: 0px\">" + isInternalStr + "</td></tr><tr><td valign=\"top\">" + message.TicketMessage + "</td><tr></table></td></tr>";

        return response;
    }
  • 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-24T22:20:21+00:00Added an answer on May 24, 2026 at 10:20 pm

    Your controller should be of type ActionResult and as mr.nicksta said, should be made in a view.

    public ActionResult AddMessage(string textMessage, bool isInternal, int ticketID)
    {
        ...
        return View(message);
    }
    

    and then create a view with the same as the controller, strongly-typed with Message.

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Message>" %>
    

    Where you create the display. You could even do this as a partial view to it can be included in other pages more easily.

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

Sidebar

Related Questions

This is probably jquery basics, but I can't find a solution after much googling.
I found this solution which works, but I find it hard to believe there
I have this solution for a single button: myButton.Attributes.Add(onclick, this.disabled=true; + GetPostBackEventReference(myButton).ToString()); Which works
We have a reporting solution that works like this. User orders the report to
So the current setup where I work bugs me, but I can't think of
is this solution possible in asp.net dragging picturebox inside winform on runtime i just
This was just what I was thinking for this solution and I would like
if your app use this solution , do do you plan port the app
I am currently stuck in the design of this solution. The data layer design
Sorry for the Windows developers out there, this solution is for Macs only. This

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.