Diego
Diego

Reputation: 2362

mvc partial view onsubmit form send data from parent view

I am developing MVC 5 App. I have a Parent View that call a Partial View, where user can Load a Image.

On Submit a call a .Ajax defined in Parent view that call Method/Controller.

What I need is to send to the controller data I have in Parent View. Is that Posible?

Here is my code.

Parent View

enter image description here

Partial View

enter image description here

.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;
            });
            

I need to send var aa='aaa' in data:

Upvotes: 0

Views: 439

Answers (1)

mfvjunior
mfvjunior

Reputation: 468

Yes it's possible. So basically I can suggest for you two ways to do what you need:

1st: You could consider putting the form element in the ParentView and change your code a little bit... 2nd: You could recover the data from the parent view and serialize it together to send to your action.

So, from the second option it would be something like:

var parentInformation = 'aaa';
var formdata = new FormData($(this).get(0));
formdata.ExpectedParentOnPropertySide = parentInformation;

Please, I hope this solve your problem

Upvotes: 1

Related Questions