0

I have a program that is developed in MVC 3 Razor Syntax but whenever I am posting to the controller with a file it doesn't work but if I just post to the controller without a file it works. What could be the problem ? Here's my Code:

@using (Html.BeginForm("UpdateFile", "AdministerFiles", FormMethod.Post, 
new {enctype = "multipart/form-data"})) 

 {
    string title = null;
    string description = null;
    string filename = null;
    int dataid = 0;
    int filesize = 0;
    string filepath = null;
    foreach (var fileDetails in ((RefDataLinks_mst[])@Model[1]))
    {
        title = fileDetails.DataTitle;
        description = fileDetails.Description;
        filename = fileDetails.DataFileName;
        dataid = fileDetails.DataID;
        filesize = fileDetails.FileSize;
        filepath = fileDetails.DataFilePath;
    }

    <div id="updateLeftTopPart">
        <label class="addFileLabel"for="title">Title : </label><textarea rows="3" cols="50" name="title" required>@title</textarea> <br /> <br />    
    </div>

    <div id="updateRightTopPart">
        <label for="description">Description : </label><textarea rows="2" cols="50" name="description" required>@description</textarea>

    </div>
    <div id="updateLeftPart">
        <label>Existing File : </label><label><a href="/BrowseData/DownloadFile?catID=@catid&filename=@filename&filepath=@filepath">@filename</a></label>
    </div>

    <div id="updateUploadFile">
        <label for="file">Upload New File Here :</label><input type="file" name="file" id="file"/>
    </div> 

        <input type="hidden" value="@catid" name="catid"/> 
        <input type="hidden" value="@filename" name="existingFile"/> 
        <input type="hidden" value="@dataid" name="dataid"/> 
        <input type="hidden" value="@filesize" name="filesize"/> 
    <div id="updateActions">
        <input type="submit" value="Update File" />
        <input type="reset" value="Reset" />
    </div>           
 }

These are the parameters of my Controller:

public ActionResult UpdateFile(HttpPostedFileBase file, int catid, int dataid, string title, string existingFile, string description, int filesize)

Whenever I post, The browser is saying that The connection to the server was reset while the page was loading. What could be the problem ?

4

1 回答 1

3

每当我发布时,浏览器都会说在页面加载时与服务器的连接已重置。可能是什么问题呢 ?

您可以使用该<httpRuntime>元素在 web.config 中增加的默认 4MB 限制。

<!-- Allow files up to 100MB to be uploaded -->
<!-- Also increase the execution timeout as uploading
100 MB files could take some time and ASP.NET won't wait that long -->

<httpRuntime maxRequestLength="102400" executionTimeout="3600" />

顺便说一句,如果您在 IIS 7+ 中托管应用程序,您还需要将 调整requestLimits为相同的值(这次以字节为单位):

<system.webServer>
    <security>
        <requestFiltering>
            <!-- Limit file uploads to 100MB -->
            <requestLimits maxAllowedContentLength="104857600" />
        </requestFiltering>
    </security>
</system.webServer>
于 2012-06-20T09:31:17.963 回答