Child actions are restricted from executing redirect actions within the modal form in my application

I'm encountering an issue in my modal form that is displaying the following error:

Child actions are not allowed to perform redirect actions.

This snippet shows my controller:


     public ActionResult Create()
     {
        return PartialView();
     }
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "Id,Title")] TypePart typePart)
    {
        try
        {
            if (ModelState.IsValid)
            {
                db.TypeParts.Add(typePart);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
        }
        catch
        {

        }
        return PartialView(typePart);
    }

In addition, here is a glimpse of my view:


  <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Add</button>
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
      <div class="modal-content">
          <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
              <h4 class="modal-title" id="myModalLabel">Add</h4>
          </div>
          <div class="modal-body" id="bodymodal">
             @Html.Action("Create","TypeParts")

          </div>

      </div>
  </div>

Answer №1

Have you ever tried using:

@Url.Action("Create","TypeParts")

instead of
@Html.Action("Create","TypeParts")

As suggested in this solution, it could potentially resolve the issue at hand.

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

Last online activity on a website

I need to record the exact time when a user last interacted with a website - whether they clicked the mouse, typed on the keyboard, or moved the cursor. By capturing this timestamp, I can calculate the remaining duration until the Web Token expires. ...

finding the relative path based on a given URL

Struggling to extract a relative path from a URL. For example, from , I want to get /my/path. I attempted the following: url = 'http://test.com/my/path'; console.log(url.replace(/^(?:\/\/|[^\/]+)*/)); Unfortunately, I am only ...

Exploring the intricacies of iterating within the .append function in

I have received 2 arrays of elements from PHP. I saved the elements in 2 variables in javascript and then looped through one variable to create a table displaying the elements. Now, I am trying to append another element and iterate through the second arra ...

What is the best way to deduct a variable's previous value from the final value, ensuring that the total value does not surpass a specific limit?

For instance: let num = 20; const sub = 6; const add = 10; num = num - sub; num = num + add; if (num > 20){ num = 20; } console.log("Only 6 was actually added to var num before reaching its maximum value"); Is there a way to adjust the console log ...

Enhancing user experience with dynamically resized Jumbotron images based on screen sizes in HTML

I am experiencing an issue with the jumbotron images on my website where they become increasingly zoomed in as the screen size decreases, and are extremely zoomed in on mobile devices. Is this a normal behavior of jumbotrons? I do understand that the image ...

using jquery to select the nearest or following div

My HTML structure is as follows: <table> <tr> <td> <button class="popup" id="$row[0]"></button> </td> </tr> </table> <div class="details"> <div id="section-2"> </div> < ...

How can I store the results of a function in Javascript on the website?

Hello everyone, I have a question about my website. I'm relatively new to JavaScript and programming in general, so I'm hoping this is an easy fix. Currently, I have a simple counter function set to an image on my website. Here is the code snippe ...

Steps to hide a div after it has been displayed once during a user's session

After a successful login, I have a div that displays a success message and then hides after 4 seconds using the following JavaScript code: document.getElementById('success').style.display = 'none'; }, 4000); While this functionality wo ...

What is the process for starting a game with a 'Start' button on the website?

Looking to create an engaging online game experience? Want to add a 'Launch' button on your game site to kickstart the client side game? Check out examples from popular online games, such as this one. How can you implement this feature seamlessly ...

Error: The parent class is not defined as an object

My program is currently attempting to utilize this.state, but I encountered an error. Can anyone provide assistance on resolving this issue? https://i.stack.imgur.com/wgxBf.png ...

The Bootstrap datetimepicker fails to function properly within the Stackable Bootstrap modal

Issue with Bootstrap datetimepicker not functioning within a Stackable Bootstrap modal. I incorporated the bootstrap-modal plugin (discovered on https://github.com/jschr/bootstrap-modal/) to display stackable modals in one form. Attempting to include the b ...

The jQuery mouseout event is activated whenever my tooltip is hovered over

Recently, I encountered an issue with a menu that adds a https://i.sstatic.net/A0J2U.png Within the menu, there is jQuery code that functions to add a class on hover and remove it on mouse-out. The code snippet looks something like this... $(document).r ...

Using an if-else statement in PHP to select and play an iframe from two available options

To enhance the user experience on my website, I am looking to incorporate an automated selection process for playing videos using iframes. Specifically, I need a decision block in PHP/JavaScript that can dynamically choose between two iframes based on the ...

Ensure that text input is restricted from containing any HTML or script tags when utilizing the Web API within an HTML page

On a html page, there are two text boxes provided for entering Employee Name and Employee Age, along with a Save button. Clicking this button triggers the Web API method called SaveEmployeeData to save the data. This Web API is hosted on an asp.net website ...

What is the most effective way to ensure a document is ready conditionally with AngularJS

I am currently utilizing ASP.NET MVC in combination with AngularJS for my project. I have a link that sends a request to an MVC Action, which then redirects to a view. In this view, there is a registered JavaScript file that loads a function inside angular ...

Oops: Looks like there is already a request for 'PUBLIC_requestAccounts' pending from http://localhost:3000. Just hold tight for now

There comes a moment when an unexpected error arises and fails to establish a connection with your wallet. if (window.ethereum) { console.log("11") const connect = async () => { const account = await window.ethereum.request({ ...

Fetching an image from an external API with NestJs: A beginner's guide

Recently, I started using a new framework for coding and found it quite amusing. However, I've run into a roadblock and now seek some assistance. The issue I'm facing is rather common in other frameworks or programming languages. I need to fetch ...

Assign the variable of one function to another function

I have a collection of buttons with usernames as values (such as jason, chan, brad, etc.). When a user clicks on a button, it is moved to a specific div. For example: <input type="button" onClick="nano();" id="name1" class="names" name="jason" value=" ...

React infinite scroll component fails to trigger the next function

Implementing the infinite scroll feature with react-infinite-scroll-component requires configuring the component as follows: <div id="scrollableDiv" style={{ height: 300, overflow: "auto" }}> <InfiniteScroll dat ...

Investigate the CSS display property of an element using JavaScript

Can JavaScript be used to determine if an element's CSS display == block or none? ...