Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:ProjectsSVNStormbreakerrunkStormbreaker.DashboardControllersDashboardController.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>            
<% } %>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
327 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 srcSystemWebMvcMvcFormCollection.cs. The team is aware of it and a fix is planned for the next preview.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...