0
我有一個mvc 3頁面,我希望能夠使用silverlight將圖像上傳到我的網站上傳並在上傳時顯示進度欄和取消按鈕。但我一直在我的控制器爲HttpPostedFileBase參數獲取空值。silverlight 4文件上傳到mvc 3控制器HttpPostedFileBase爲空
這裏是我的Silverlight上傳代碼...
var client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "multipart/form-data";
client.OpenWriteCompleted += (sender1, e1) =>
{
PushData(stream, e1.Result);
e1.Result.Close();
stream.Close();
};
client.UploadProgressChanged += (sender1, e1) =>
{
this.pbStatus.Value = e1.ProgressPercentage;
};
// get uri from params
param = App.Current.Host.InitParams["url"];
var uri = new Uri(param, UriKind.Relative);
client.OpenWriteAsync(uri, "POST");
數據推法...
private void PushData(Stream input, Stream output)
{
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
{
output.Write(buffer, 0, bytesRead);
}
}
我的控制器代碼...
[HttpPost]
public ActionResult UploadTexture(HttpPostedFileBase file)
{
}
文件PARAM在控制器被調用時,在我的控制器中爲null。任何人都知道我在做什麼錯了?
我見過實現一個IHttpHandler的例子,但我試圖避免這樣做,並堅持使用直接mvc 3控制器。