我正在尝试将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>
<% } %>
答案 0 :(得分:19)
这是MVC 2 RC中确认的错误。如果您有the MVC source,则可以从FormCollection.GetValue()中删除String.IsNullOrEmpty()检查,重新编译和重新部署。 FormCollection类位于 src \ SystemWebMvc \ Mvc \ FormCollection.cs 。团队意识到了这一点,并计划在下一次预览中进行修复。
答案 1 :(得分:1)
在尝试查看Orchard CMS时遇到同样的问题。让我们希望他们尽快解决。