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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:07:42+00:00 2026-06-03T18:07:42+00:00

In a partial view, I am using MVCs Ajax.Beginform like followed: <div id=divToReplace> @using

  • 0

In a partial view, I am using MVCs Ajax.Beginform like followed:

<div id="divToReplace">
    @using (Ajax.BeginForm("Action", "Controller,
                           new AjaxOptions
                           {
                               InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace,
                               UpdateTargetId = "divToReplace"
                           },
                           new
                           {
                                id = "formID"
                           }))
    {
        ...
</div>

When submitting the form, I would expect that the hole div “divToReplace” is replaced by the answer (the partial view again). But instead the inner html of the div “divToReplace” is replaced by the answer, so the beginning of the partial view looks like this:

<div id="divToReplace">
    <div id="divToReplace">
           ...

What am I doing wrong?

  • 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-03T18:07:45+00:00Added an answer on June 3, 2026 at 6:07 pm

    Well, after a certain time, I ran into the same problem and now I wanted to make it clear so I had a look in jquery.unobtrusive-ajax.js and the responsable function:

    function asyncOnSuccess(element, data, contentType) {
        var mode;
    
        if (contentType.indexOf("application/x-javascript") !== -1) {  // jQuery already executes JavaScript for us
            return;
        }
    
        mode = (element.getAttribute("data-ajax-mode") || "").toUpperCase();
        $(element.getAttribute("data-ajax-update")).each(function (i, update) {
            var top;
            switch (mode) {
                case "BEFORE":
                    top = update.firstChild;
                    $("<div />").html(data).contents().each(function () {
                        update.insertBefore(this, top);
                    });
                    break;
                case "AFTER":
                    $("<div />").html(data).contents().each(function () {
                        update.appendChild(this);
                    });
                    break;
                default:
                    // Changed this line because of generating duplicate IDs
                    //$(update).html(data);
                    $(update).html($(data).html());
                    break;
            }
        });
    }
    

    As you can see in the default part, the answer was not replacing the updatetargetid but replaced its content with the answer. Now I take the inner part of the answer and everything works fine!

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

Sidebar

Related Questions

This is the code in my partial view - @using (Ajax.BeginForm(SaveLayout, new AjaxOptions {
I have something like this: Main view: @model AuthorViewModel @using (Html.BeginForm(Action, Controller, FormMethod.Post, new
I have the following form in a partial view @model PartDetail @using (Ajax.BeginForm(Create, Part,
I am using the partial view with the ajax.beginform. In that partial view page,
I am updating a div with a partial view by using something like this:
Using the following JQuery/AJAX function I'm calling a partial view when an option is
I've got view: @using (Html.BeginForm(ProcessRoute, Calculator)) { @Html.TextBox(CityArrival, null, new { @style = width:
In my code I am using a partial view (call it PV1) <div id=div_1>
I am loading a partial view in the popup using following code: <div id=Mydiv
I am loading a partial view into a main view using ajax but struggling

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.