How to implement an JsonResult method to pass by http://valums.com/ajax-upload/ extra parameters?
-
14-04-2021 - |
Question
The website http://valums.com/ajax-upload/ says that:
Sending additional params
To add a parameter that will be passed as a query string with each upload use params option.
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader'),
action: '/server-side.upload',
// additional data to send, name-value pairs
params: {
param1: 'value1',
param2: 'value2'
}
});
My question is: How do I should implement
public JsonResult UploadFile(string qqfile, ????)
{
}
correctly to pass 'value1' and 'value2'?
Thank you!!!
Solution
You can use the model binder for that. Create a class with properties, where the names of the properties are equal to the params you send:
public class UploadPostModel
{
public string param1 {get;set;}
public string param2 {get;set;}
}
In the action, use the Postmodel. The default model-binder will automatically populate the class.
public JsonResult UploadFile(string qqfile, UploadPostModel pm)
{
//use the values
}
ofcourse you could also put the qqfile in the Model.
OTHER TIPS
public JsonResult UploadFile(string qqfile, string param1, string param2)
{
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow