ASP.NET MVC 2问题的UpdateModel [英] ASP.NET MVC 2 problem with UpdateModel

查看:141
本文介绍了ASP.NET MVC 2问题的UpdateModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的UpdateModel(myItem,的FormCollection)与asp.net MVC 2,但它无法与下面的堆栈跟踪。

 在System.Web.Mvc.FormCollection.GetValue(字符串名称)
   在System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext,ModelBindingContext的BindingContext)
   在System.Web.Mvc.Controller.TryUpdateModel [的TModel(的TModel模型,字符串preFIX,字符串[] includeProperties,字符串[] excludeProperties,IValueProvider valueProvider)
   在System.Web.Mvc.Controller.TryUpdateModel [的TModel(模型的TModel,IValueProvider valueProvider)
   在Stormbreaker.Dashboard.Controllers.DashboardController`1.Update(的FormCollection集合)在D:\\项目\\ SVN \\旋风特务\\干线\\ Stormbreaker.Dashboard \\ \\控制器DashboardController.cs:23行
   在lambda_method(ExecutionScope,ControllerBase,对象[])
   在System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary`2参数)
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2参数)
   在System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter过滤器,ActionExecutingContext preContext,Func`1续)

我的动作看起来是这样的:

 的[AcceptVerbs(HttpVerbs.Post)
    [ValidateInput(假)]
    公众的ActionResult更新(的FormCollection集合){
        的UpdateModel(CURRENTITEM,集合);
        CURRENTITEM =(T)_repository.Update(CURRENTITEM);
        返回RedirectToAction(编辑,新的{PAGEPATH = CurrentItem.UrlSegment});
    }

...我的表是这样的:

 &LT;使用%(Html.BeginForm(更新,仪表盘,FormMethod.Post,新{NAME =editForm}))%GT;
&LT;%{%GT;
    &LT; D​​IV&GT;
        &所述;%= Html.EditorForModel()%&GT;
        &LT;输入类型=提交值=保存/&GT;
    &LT; / DIV&GT;
&LT;%}%GT;


解决方案

这是MVC 2 RC确认的错误。如果您有的MVC源,可以去掉字符串从FormCollection.GetValue .IsNullOrEmpty()检查(),重新编译和重新部署。该班的FormCollection在的src \\ SystemWebMvc \\的mvc \\ FormCollection.cs 。该小组是意识到这一点,并修复被计划在未来preVIEW。

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>            
<% } %>

解决方案

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.

这篇关于ASP.NET MVC 2问题的UpdateModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆