13

我正在尝试将 updatemodel(myItem, formcollection) 与 asp.net mvc 2 一起使用,但它因下面的堆栈跟踪而失败。

   at System.Web.Mvc.FormCollection.GetValue(String name)
   at System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
   at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, String prefix, String[] includeProperties, String[] excludeProperties, IValueProvider valueProvider)
   at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, IValueProvider valueProvider)
   at Stormbreaker.Dashboard.Controllers.DashboardController`1.Update(FormCollection collection) in D:\Projects\SVN\Stormbreaker\trunk\Stormbreaker.Dashboard\Controllers\DashboardController.cs:line 23
   at lambda_method(ExecutionScope , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

我的动作是这样的:

    [AcceptVerbs(HttpVerbs.Post)]
    [ValidateInput(false)]
    public ActionResult Update(FormCollection collection) {
        UpdateModel(CurrentItem, collection);
        CurrentItem = (T)_repository.Update(CurrentItem);
        return RedirectToAction("edit", new { pagePath = CurrentItem.UrlSegment });
    }

...我的表格如下所示:

<% using (Html.BeginForm("Update","Dashboard", FormMethod.Post, new { name = "editForm" } )) %>
<% { %>
    <div>
        <%=Html.EditorForModel() %>
        <input type="submit" value="Save" />
    </div>            
<% } %>
4

2 回答 2

19

这是 MVC 2 RC 中已确认的错误。如果您有MVC 源,则可以从 FormCollection.GetValue() 中删除 String.IsNullOrEmpty() 检查,重新编译并重新部署。FormCollection 类位于src\SystemWebMvc\Mvc\FormCollection.cs。团队已经意识到这一点,并计划在下一次预览版中进行修复。

于 2009-12-21T01:27:18.620 回答
1

尝试查看 Orchard CMS 时在这里遇到了同样的问题。让我们希望他们尽快修复它。

于 2010-01-04T14:01:45.053 回答