MVC + 表单:提交错误

3
每当我尝试在我的MVC网站中进行简单的表单提交时,就会出现以下错误:
"Either BinaryRead, Form, Files, or InputStream was accessed before the internal storage was filled by the caller of HttpRequest.GetBufferedInputStream."
描述:当前Web请求执行期间发生未处理的异常。请查看堆栈跟踪以获取有关错误的更多信息以及其在代码中的起源。
异常详细信息:System.InvalidOperationException: Either BinaryRead, Form, Files, or InputStream was accessed before the internal storage was filled by the caller of HttpRequest.GetBufferedInputStream.
我的示例表单和操作非常基本...
@using (Html.BeginForm("Create", "Form"))
{
    <div class="row action">
        <div class="row">
            First name: <input type="text" name="fname"><br>
            Last name: <input type="text" name="lname"><br>
        </div>
        <input type="submit" id="save" class="btn" value="Save"/>
        <input type="button" id="cancel" class="btn" value="Cancel"/>
     </div>
}

我的Controller动作甚至更加基础...

[HttpPost]
    public ActionResult Create(FormCollection collection)
    {
        try
        {
            // TODO: Add insert logic here

            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }

如果您删除 FormCollection collection 参数,这会解决问题吗? - Justin Helgerson
这会导致出现“找不到资源”的404错误。它试图访问“/Create”,但它从未触发我的操作内的断点。 - Codey
你为什么在标签中放置了MVC4和MVC5?你尝试升级或做了什么可能导致这种情况的操作吗? - Brad C
这是一个网站迁移。是的,在迁移过程中,该网站从MVC 3.0升级到了MVC 5。 - Codey
@Codey - 现在只是为了测试,你能否将 FormCollection collection 替换为 string test,看看之前发布的错误是否已经消失?我怀疑你的问题与 FormCollection 的使用有关。 - Justin Helgerson
显示剩余2条评论
1个回答

0
请分享您的route.config文件,这可能有助于解决此问题。如果可以的话,请尝试从Html.BeginForm()中删除参数,删除操作和控制器的名称。由于MVC具有强大的命名系统,因此我们不需要添加该信息。
如果上述方法无法解决您的问题,请分享您的路由文件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接