ASP.NET MVC 2 UpdateModel 问题
我尝试将 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>
<% } %>
I'm trying to use updatemodel(myItem, formcollection) with asp.net mvc 2 but it fails with the stack trace below.
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)
My action looks like this:
[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 });
}
... and my form looks like this:
<% using (Html.BeginForm("Update","Dashboard", FormMethod.Post, new { name = "editForm" } )) %>
<% { %>
<div>
<%=Html.EditorForModel() %>
<input type="submit" value="Save" />
</div>
<% } %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 MVC 2 RC 中已确认的错误。如果您有MVC 源,则可以删除 String.IsNullOrEmpty () 从 FormCollection.GetValue() 检查,重新编译并重新部署。 FormCollection 类位于 src\SystemWebMvc\Mvc\FormCollection.cs。团队已经意识到这一点,并计划在下一个预览中进行修复。
This is a confirmed bug in MVC 2 RC. If you have the MVC source, you can remove the String.IsNullOrEmpty() check from FormCollection.GetValue(), recompile, and redeploy. The FormCollection class is at src\SystemWebMvc\Mvc\FormCollection.cs. The team is aware of it and a fix is planned for the next preview.
在尝试查看 Orchard CMS 时遇到了同样的问题。希望他们尽快修复它。
Had the same issue here when trying to look at Orchard CMS. Lets hope they fix it soon.