Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I got the same Exception when I was experimenting with various Data binding techniques in MVC 2.0. My action method:<BR/></p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public ActionResult FindPersonList(FormCollection form) { PersonList personList = new PersonList(); if (TryUpdateModel(personList, form.ToValueProvider())) { //....Do something } else { Add Error message return View("SubmittedView"); } return View("GoNextView"); } </code></pre> <p><BR/> The view Contains only simple strigs and they are not NULL.</p> <p>The Exception:<br/></p> <pre><code>System.ArgumentException was unhandled by user code Message="Value cannot be null or empty. Parameter name: name" Source="System.Web.Mvc" ParamName="name" StackTrace:..... </code></pre> <p>I followed the suggestion from this link:<br/> <a href="https://stackoverflow.com/questions/1936970/asp-net-mvc-2-problem-with-updatemodel">ASP.NET MVC 2 problem with UpdateModel</a></p> <p>I downloaded Mvc source code and debugged it. I found out that the controllerContext is NULL which causes the above Exception. Why controllerContext is Null I don't know!</p> <p>I tried to set controllerContext during Unit test using Mock object and it worked fine.</p> <pre><code>[Test] public void FindPersonListActionTest() { using (new SessionScope())//Related to ActiveRecord from Castle project ORM { FormCollection form = new FormCollection(); form.Add("BaseSearchKey", "Thabet"); form.Add("DepSearchKey", "Yourtan"); form.Add("name", "Some name"); controller.ControllerContext = new FakeControllerContext(controller); Assert.IsNotNull(controller.HttpContext, "HttpContext is NULL"); Assert.IsNotNull(controller.ControllerContext, "ControllerContext is NULL"); var result = controller.FindPersonList(form) as ViewResult; Assert.IsNotNull(result, "ViewResult is NULL"); var list = (PersonList)((ViewResult)result).ViewData.Model; Assert.IsNotNull(list, "Controller Model is NULL"); } } </code></pre> <p>The same Exception happens when using UpdateModel:<br/></p> <pre><code>UpdateModel(personList, form); </code></pre> <p><BR/> I think it is a bug, because I tried default binding using action that takes a model as an arg, and behaves normally: <BR/></p> <pre><code>public ActionResult FindPersonList(PersonList personList){....} </code></pre> <p><BR/> And it works fine.</p> <p>However I would like very much to understand what was set controllerContext to Null.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload