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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:51:15+00:00 2026-05-14T14:51:15+00:00

I have a page as follows: <% using (Ajax.BeginForm(AddAnswer,Marketplace,new AjaxOptions() {HttpMethod = POST })){

  • 0

I have a page as follows:

<% using (Ajax.BeginForm("AddAnswer","Marketplace",new AjaxOptions() {HttpMethod = "POST" })){ %>

AddAnswer action adds some data to db. What I want to do is: when answer has been successfully added, append #answers div with the current answer passed to controller. When answer has not been successfully added to db – I would like to display appropriate error in #errors div. How can I 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-05-14T14:51:15+00:00Added an answer on May 14, 2026 at 2:51 pm

    Here’s what I can suggest:

    Controller:

    [HttpPost]
    public ActionResult AddAnswer(string Value)
    {
        // TODO: Try to insert the answer value into the database
        // and return a JSON object that contains the attempted value
        // and an error message if necessary
        return Json(new { Answer = Value, ErrorMessage = "" });
    }
    

    View:

    <% using (Ajax.BeginForm("AddAnswer", "Home", 
           new AjaxOptions { HttpMethod = "POST", OnSuccess = "success" })) { %>
        <%= Html.TextBoxFor(x => x.Value) %>
        <input type="submit" value="Add answer" />
    <% } %>
    
    <div id="errors"></div>
    <div id="answers"></div>
    
    <script type="text/javascript">
        function success(arg) {
            var obj = arg.get_response().get_object();
            // I apologize for the ugliness that follows, I don't know MS Ajax
            // but this might written better:
            if (obj.ErrorMessage === '') {
                var answer = document.createElement('div');
                answer.appendChild(document.createTextNode(obj.Answer));
                document.getElementById('answers').appendChild(answer);
            } else {
                document.getElementById('errors').innerHTML = obj.ErrorMessage;
            }
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using JQuery .ajax my content is put into a new page instead of
I currently have a page which is declared as follows: public partial class MyPage
I have a FileUpload Control and a image control on asp.net page as follows
In my view, I have included the Master page as follows: <%@ Page Title=
I have an html page with a single-line javascript comment as follows: // {key1:value1},
I have a html file like following: <form action=/2811457/follow?gsid=3_5bce9b871484d3af90c89f37 method=post> <div> <a href=/2811457/follow?page=2&amp;gsid=3_5bce9b871484d3af90c89f37>next_page</a> &nbsp;<input
I have a SELECT element in a form which I'm populating using AJAX when
I load some html using AJAX, this works fine, one of the bits that
I have a web page that is using JQuery to communicate with the backend.
My page is fully postback twice. I am using master page with AJAX. 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.