Domanda

I use a jQuery plugin called jscroller, which uses jquery.ajax to make ajax calls. I need to pass in all parameters from a search form, and deliver them to mvc controller, and I think the best way is to put in 'data' field the following expr':

$('#formId').serialize();

My problems is that I need to pass, along with the form values, a 'page' value which is being changed with each call.

How can I put the page value, along with the 'serialize' expression in 'data' field, or is there really another more efficient way to do it?

È stato utile?

Soluzione

I think

var formdata = $('#formId').serialize();
data: (formdata ? formdata + "&" : "") + "page=" + pageId

will solve your problem

Altri suggerimenti

You can create a new FormData and just add the parameter on that variable too

var formData = new FormData(); 
formData.append('pageId', pageId);

var your_form = $('#formId').serializeArray();
$.each(your_form,function(key,input){
   formData.append(input.name,input.value);
});

$.ajax({
    url: 'url_here',
    data: formData,
    contentType: false,
    processData: false,
    type: 'POST'
});

so at MVC controller you will be able to access like

var pageId = Request.Form.Get("pageId");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top