Why do I see my footer displayed twice on the page?

<div class="navbar-collapse collapse">
  <ul class="nav navbar-nav">
    <li>@Html.ActionLink("Home", "Index", "Home")</li>
    <li>
      @Ajax.ActionLink("Imagenes List", "Images", "Home", new { page = 0 }, new AjaxOptions()
      {
        HttpMethod = "GET",
        UpdateTargetId = "divImage",
        InsertionMode = InsertionMode.Replace
      })
    </li>
  </ul>
</div>

Two links in the _Layout: @Html.ActionLink and @Ajax.ActionLink

A div container used for AJAX calls

<div id="divImage" class="container body-content">
  @RenderBody()
  <hr />
</div>

And a footer.

<footer class="container body-content">
  <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
</footer>`

The issue arises with @Ajax.ActionLink showing the footer twice compared to @Html.ActionLink.

The problem was resolved by changing the return for the "Images" action to return PartialView() or setting Layout = null;

However, I am curious why only AJAX requires this fix. Is my solution adequate?

My assumption is there might be something related to CSS causing this issue, but I'm unsure what to look for.

Answer №1

When working with AJAX, it becomes necessary as it involves injecting content into an already existing view. The initial rendering of the view includes the entire layout, and then additional layouts are inserted during the AJAX call.

In contrast, in the other scenario, only the main view is rendered, resulting in a single layout being used.

Answer №2

To include it in the body section, follow these steps (this is the main cshtml file):

-body id="miau"- @Html.Partial("PartialView1", Model.partialModel) -/body-

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What method can I use to serialize data into XML format without needing an .xsd schema?

I am working on an ASP.NET MVC (5) project where I need to perform custom XML serialization. Before I proceed, I want to clarify that I wasn't entirely sure if this is the right place to ask this question or if it should be directed to a different for ...

`Explore SQL data using modal window`

Hey there, I'm in a bit of a pickle with my code. As someone who's just dipping their toes into the world of AJAX and has a vague understanding of PHP, I find myself lost in trying to figure out where things went wrong. My challenge lies in fetc ...

Using bootstrap's center-block class, you can easily center

I'm attempting to center the content of a form. <div class="login-container"> <div class="center-block"> <form action="/joinChart" method="get"> <input name="username" id="username" type="text"><br><br> ...

Bootstrap4: What could be causing the adjacent row cell to remain left-justified instead of being centered as intended with mx-auto?

I've been working on creating a responsive header using Bootstrap4. The main goal is to have the logo displayed as left-justified text and the menu items as right-justified when the viewport is large, then transition to both being centered in a "small ...

What's the reason for the icon not updating in the responsive mode?

I am venturing into the world of responsive web design for the first time. My aim is to create a website menu that drops down when the menu icon is clicked, using the onclick command in JavaScript. However, upon inspecting my browser, I noticed an uncaught ...

Combining Django, ajax, and modal form in Bootstrap 5: A step-by-step guide for successful implementation

I've been struggling to implement an Ajax request for a while now. Whenever it's successful, I want it to redirect, and if it fails, show an error message. I've tried various methods that I can't seem to remember now. It would be greatl ...

transferring data through AJAX using the POST method

When attempting to utilize the POST method to send a variable containing a name to a server asynchronously, I encountered an error message: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data. Unfortunately, this error was n ...

A guide on configuring Flexbox to consistently display three columns

For the website I'm working on, I've utilized Flexbox to properly align the items. Within the div .main, I have organized the content in separate divs. These are the CSS properties that I've applied: .main{ margin: 0 auto; /*max-height: ...

In order to activate the VScode Tailwind CSS Intellisense plugin, I have discovered that I need to insert a space before

I recently followed the installation guide for using Tailwind with Next.js Here is a snippet from my tailwind.config.js file: /** @type {import('tailwindcss').Config} */ module.exports = { content: [ "./app/**/*.{js,ts,jsx,tsx}", ...

The error at line 72 of proxyConsole.js is: TypeError - Unable to access the 'default' property of an undefined object

I am new to using react redux loading bar and redux forms After clicking a button, I want the loading bar to display. The issue arises when I try to load the loading bar, resulting in the following error message: proxyConsole.js:72 TypeError: Cannot read p ...

What measures can we take to prevent text from dropping to the next line when neighboring text wraps around to multiple lines?

Make sure to review the problem statement in the plnkr linked below. http://plnkr.co/edit/ojt3l3ljNYOA6HDq .d { width: 200px; background: red; text-align: center; >div { display: inline } } .a { float: left; } .c { float: right; ...

The CSS :lang() selector targets elements within documents that do not specify a particular language

Can elements that do not have a language set or inherited, meaning they are in an unspecified ("unknown") language, be targeted? Facts The language of an HTML document or element can be specified using the HTML lang attribute, for example: <html lang=& ...

Eliminating a line break that appears after incorporating a list into a paragraph

Currently, I am in the process of developing a website where I need to input information. To display this information, I decided to use a list within a paragraph. However, I noticed that after the list name, the text moves to another line which is not wh ...

Implementing jQuery stylesheet using a bookmarklet

Here's a question that may seem silly, but I'm looking to quickly apply CSS styles to a webpage by clicking on a bookmarklet. It will definitely save me time :) For example, this code does the trick: javascript:void( jQuery( ".fancybox-overlay- ...

What could be causing justify-content: flex-start; to not function as expected?

Can someone help me with my flexbox navbar? I set the justify-content property to flex-start, but the content inside the container is not aligning correctly. You can see the output and code here: output html, body { backgr ...

Learn how to smoothly scroll to the top of a div by clicking on a team name

CSS Code .hover-div { position:absolute; margin-top:-150px; visibility:hidden; transition:all 0.5s linear 0s; } .team_hover:hover + .hover-div { margin-top:0px; visibility:visible; } .hover-div:hover { margin-top:0px; visi ...

To enhance the MUI v5 table row, simply apply a border when the mouse hovers

After working on creating a table with Material UI v5, I encountered an issue where I wanted to add a blue border to the table row when the mouse pointer hovered over it. I attempted several methods and did thorough research, but unfortunately, I was unab ...

Struggling with retrieving the $id variable from the view in both the controller and the database through Ajax

While checking my view, I noticed that the variable $id is visible. However, when I send it through Ajax, it ends up as NULL in the database. The way I'm sending the variable $id from the view using Ajax is like this: $.ajax({ url:'{ ...

Utilizing jQuery to dynamically load Wordpress pages through ajax requests

I'm currently setting up a Wordpress theme that utilizes AJAX to load pages instead of posts. I tried following this particular tutorial but so far, I haven't been successful in getting the correct pages to load. The links to the posts are being ...

What is the best way to retrieve the output from an Ajax request when there are two outputs - one for a PHP echo and another for the Ajax

After successfully fetching the data from the database, I encountered an issue. I want to use Ajax requests to display the results. The problem arises when the results/output are displayed twice. Specifically, the *first output is displayed through Ajax (a ...