How to implement an JsonResult method to pass by http://valums.com/ajax-upload/ extra parameters?

StackOverflow https://stackoverflow.com/questions/8759865

質問

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!!!

役に立ちましたか?

解決

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.

他のヒント

public JsonResult UploadFile(string qqfile, string param1, string param2)
{

}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top