0

我的表单在 MVC3 中发布数据时遇到问题。在本地,表单 POST 成功,但在实时服务器上,当有大量发布数据时,会显示 404 而不是成功页面。数据来自包含在 POST 中的模型,其中通常有很多数据,其中一些我正在使用。我已经查看了更改 web.config 中的设置,但这并没有帮助。以下是我的一些代码片段:

风景:

 @using (Html.BeginForm("Bookmarked", "Bookmarklet", Model, FormMethod.Post))
{

<div class="form">
@Html.ValidationSummary(false)

 @Html.TextBoxFor(a => a.Url, new { @class = "hidden" })
 @Html.TextBoxFor(a => a.SelectedImage, new { @class = "selected-image hidden" })

 <div class="form-left">
    <div class="row">
        <label>
            Name:
        </label>
        @Html.TextBoxFor(a => a.Name, new { @class = "textbox" })
        @Html.ValidationMessageFor(a => a.Name, null, new { style = "display:none" })
    </div>

    <div class="row">
        <label>
            Tags:
        </label>
        @Html.TextBoxFor(a => a.Tags, new { @class = "textbox tb-tags", @placeholder = "", onKeyUp = "submitForm(event)" })

    </div>

    <div class="row">
        <br />
        <label>
            &nbsp;</label><a href="javascript:document.forms[0].submit()" class="button fl"><span>Bookmark</span></a>
    </div>
</div>

// The controller

[HttpPost]
    public ActionResult Bookmarked(BookmarkModel initialState, BookmarkModel model)
    {
        try
        {
            HttpCookie cookie = Request.Cookies["UserGuid"];
            HttpCookie cookie2 = Request.Cookies["Username"];
            if (cookie != null && cookie2 != null)
            {
               //do stuff with model data received from the View that the POST comes from

               da.Save(model.Name, cookie.Value);
                return View();
             }
              else
                    throw new Exception("Error saving, please try again");

        }
        catch (Exception ex)
        {
            ModelState.AddModelError("", ex.Message);
            return Bookmark(model);
        }

    }

// web.config

 <system.web>
 <httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
 <compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

<pages>
  <namespaces>
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.WebPages"/>
    <add namespace="ConsumerMVC3.App_Code"/>
  </namespaces>
  </pages>
</system.web>

<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <modules runAllManagedModulesForAllRequests="true"/>
  <security>
     <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483648" />
    </requestFiltering>
  </security>
</system.webServer>

谁能给我一些建议?

谢谢,科林

4

1 回答 1

0

由于您没有节省太多,您是否考虑过为您的视图创建一个 ViewModel?它可以是您模型的一个非常概括的版本,是该特定视图所需的全部内容。它还将大大减少往返于服务器的有效负载。

于 2012-06-11T21:18:19.757 回答