Submitting an mvc partial view form to send data from the parent view

I am currently working on a MVC 5 App where I have a Parent View that includes a Partial View, allowing users to load images.

Upon submitting, the Parent view calls a .Ajax function defined within it, which in turn calls a Method/Controller.

My requirement is to send the data present in the Parent View to the controller. Is this achievable?

Below is a snippet of my code:

Parent View

https://i.stack.imgur.com/sZ6Js.png

Partial View

https://i.stack.imgur.com/TIRUN.png

.Ajax Method

          
$('#formPhoto').submit(function (event) {
    event.preventDefault();
    if ($(this).valid()) {
        var id="aaa";
        var formdata = new FormData($(this).get(0));
        $.ajax({
            url: this.action,
            type: this.method,
            data:formdata,
            processData: false,
            contentType: false,
            beforeSend: function () {
                return true;
            },
            success: function (result) {
                successPhoto();
            },
            complete: function () {
                // alert(3);
                // And so on.
            }
        });
    }
    return false;
});

In order to include var aa='aaa' in the data: parameter.

Answer №1

Absolutely! There are a couple of approaches you can take to achieve your goal:

1. First, consider placing the form element in the ParentView and making slight modifications to your code... 2. Alternatively, you can extract data from the parent view and serialize it before sending it to your action.

If you opt for the second method, your code snippet might look like this:

let parentInfo = 'aaa';
let formData = new FormData($(this).get(0));
formData.ExpectedParentOnPropertySide = parentInfo;

I hope this solution works for you!

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

Employing DOM manipulation within Vue unit tests as a last resort

What steps should I take to update my unit test in order to accurately validate the following scenario? Method: close(event) { const element = !!event?.target?.closest('#target') if (!element) { this.isVisible = false } }, Jest test: ...

Discover siblings in React component siblings

Creating a parent element (Board) that generates a list of children and provides a method to access this list can be done like so: export default class Board extends React.Component { constructor(props) { super(props); this.getList = t ...

The web server experiences a layout and functionality breakdown caused by an issue with the config.js file following the uploading process

I recently created a website. However, when I uploaded it to my hosting company's server and tested it on different browsers, the layout appeared broken. Some of the CSS files loaded properly, but certain elements and styles were not in their correct ...

After submitting a post, the click event of a button in IE 10 using jQuery is not

The uploadButton feature allows users to upload an image and store it locally. I utilize fileinput to select the image, and when uploadbutton is clicked, the image data is sent back to the server. While this functionality works smoothly in Chrome, I encou ...

Encountering issues with Node-persist on a complex Node.js application leading to missing return

I've encountered an issue with my heavy node app where I'm using node-persist to save data locally. Specifically, in a certain step of the process, I have the following code: const localdb = require('node-persist') const storage = loca ...

Tutorial on displaying historical pricing data on a chart utilizing props in Vue Chartkick

I recently discovered a chart library called Chartkick for Vue projects. If you're interested, you can check it out here: In my project, I have data passed as props to a component. However, I encountered an issue where the prop couldn't be acces ...

What is the best way to create an Office Script autofill feature that automatically fills to the last row in Excel?

Having trouble setting up an Excel script to autofill a column only down to the final row of data, without extending further. Each table I use this script on has a different number of rows, so hardcoding the row range is not helpful. Is there a way to make ...

Substitute this.bindMethod for function component

I have a class component that is structured like this: interface MyProps { addingCoord: any resetCoords: any } interface MyState { x: any y: any } class DrawerOld extends React.Component<MyProps, MyState> { width: number height: number ...

Using multiple `setState` calls without synchronization can lead to issues, especially when one of them uses a value obtained from `

In my discovery: When there are two instances of setState The first one is invoked with a value obtained from await Both calls occur in the same thread It results in a scenario where one state is updated while the other remains unchanged. For instance: ...

CSS text width going from left to right

I am attempting to create a text fade effect from left to right, inspired by the technique discussed in this answer. However, I would like the text to be concealed behind a transparent background div instead of the white background used in the example. I ...

Angular list with a repeating group of radio buttons

I have a set of 'options', which consists of the following: {Id: 1, Label: "option 1"}, {Id: 2, Label: "option 2"} Additionally, I have a list of 'products' structured as follows: {Id: 1, Name: "Name 1", Recommend: options[0]}, {Id: ...

"Concealing Querystrings in Node.js and AJAX: A Step-by-Step

I want to create a simple login form using the ajax Post method. However, I am having issues with the querystring still appearing in the URL. Can anyone help me resolve this issue? Thank you for any assistance! [ https://i.stack.imgur.com/R76O4.png http ...

Controlling the Escape Key and Clicking Outside the Material-ui Dialog Box

I am currently utilizing material-ui's dialog feature. In this setup, when a user clicks the "sign out" button, a dialog box opens with options to either confirm the sign out by selecting "yes" or cancel it by choosing "no". The issue arises when the ...

Guide on accessing the text content within a div element in HTML by triggering a button click

To extract specific text from multiple div tags, I need to trigger an event when clicking a button. <div class="col-lg-3 col-md-6 mb-4"> <div class="pricing-table pricing-secondary"> <div class="price-hea ...

The shared module for next/router is not found in the shared scope default within Next.js and @module-federation/nextjs-mf

I am working on a JavaScript Turbo repo with a host app that has the following configuration in its next.config.js: const { NextFederationPlugin } = require("@module-federation/nextjs-mf"); const nextConfig = { reactStrictMode: true, ...

Maximizing efficiency in jQueryMobile code: addressing issues with selectively integrating external JS files based on necessity

My mobile application is using jQueryMobile, and I am focused on optimizing the UI to load quickly. The application consists of more than one tool, so I want to ensure that only the relevant external JS libraries for each 'page' are loaded when n ...

The issue arises when trying to call a JavaScript function that has not been properly

Initially, write code in resources/js/app.js file function button1Clicked(){ console.log('Button 1 is clicked'); } Next, include the following code in testing.blade.php file <!DOCTYPE html> <html> <head> <meta name="cs ...

Validation with Jquery in an ASP.NET C# login form utilizing a webservice

Hi there, I've been working on a login form in asp.net that should redirect to another page. To handle user validation, I created a webservice using jQuery but I'm facing an issue where the ajax data is returning undefined and the page is not red ...

What could be causing my ajax file uploader to malfunction?

I am currently working on building an AJAX file upload module. Below is a snippet of the code I have been using: //creating a form for uploading files via AJAX FileUploader.prototype.createForm = function() { // creating a new form var form = docu ...

Error: You are not able to utilize an import statement outside of a module when utilizing the `fast-image-zoom` feature

Currently, I am attempting to integrate fast-image-zoom into my React/Next.js application and unfortunately encountering an error message that reads: SyntaxError: Cannot use import statement outside a module at Object.compileFunction (node:vm:353:18) ...