2015-09-15 57 views
1

我有一個表單上傳文件,服務器必須處理一個需要幾分鐘的大型操作。設置表單發佈超時

我的代碼:

.cshtml:

@using (Html.BeginForm("MyAction", "MyController", FormMethod.Post, 
      new { enctype = "multipart/form-data" })) 
{ 
    <input type="file" name="file"/> 
    <input type="submit" value="submit" /> 
} 

控制器:

[HttpPost] 
public ActionResult MyAction(HttpPostedFileBase file) 
{ 
    // Process a large operation here. 

    return View(); 
} 

我知道這是可能的web.config configurationserver code做到這一點。
我的問題:是否可以使用客戶端配置?

我要求使用XMLHttpRequestjQuery.ajax其可能的情況下設置超時,因爲這樣纔有可能在HTML表單標籤或什麼呢?

+2

可能重複http://stackoverflow.com/questions/579523/how-do-i- set-the-request-timeout-for-one-controller-action-in-an-asp-net-mvc-app) – musefan

+0

我更新了這個問題。這種重複現在不可用了。 –

+0

爲什麼從你的視圖代碼中設置它很重要?爲什麼不能修改控制器代碼? – musefan

回答

2

其中一個選項是創建AsyncController,然後您可以在您的操作中設置[AsyncTimeout(xxxx)]或[NoAsyncTimeout]屬性。

Here is an example on how to do it

的[如何設置一個控制器操作的請求超時在一個asp.net MVC應用](
+0

感謝您的答案,但我想與客戶端配置爲jQuery.ajax。 +1。 –

+0

@JonnyPiazzi那麼你可能會考慮從你的視圖中使用jQuery.ajax,你可以指定超時。但我會建議使用AsyncController –