title: MVC 3 split parameters in HttpPost action
body: <p>I have an MVC 3 app and I have created a generic wrapper object, which has some navigation properties and the wrapped object of T, whose values I'm editing/displaying.</p>
  
  <pre><code>public class NavigationViewModel&lt;T&gt;
  {
      public T Model { get; set; }
      public NavigationHelper NavigationHelper { get; set; }
  
      public NavigationViewModel() { }
  
      public NavigationViewModel(T model, NavigationHelper helper)
      {
          this.Model = model;
          this.NavigationHelper = helper;
      }
  }
  </code></pre>
  
  <p>My controller resolves this object nicely in an action like this:</p>
  
  <pre><code>public ActionResult Foo(NavigationViewModel&lt;Bar&gt; viewModel)
  </code></pre>
  
  <p>Code in my view looks like this:</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.Model.SomeProperty) 
  </code></pre>
  
  <p>My colleague said that that code is not nice to read. I already have a strongly typed view, the Model and this Model has another property called Model. He suggested to rename the Model property to ViewModel and I agreed with his reasoning.</p>
  
  <p>Now, the code with the renamed properties does not work anymore: NavigationViewModel viewModel is null. So I changed the signature of the HttpPost method to the following and it works again:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Foo(NavigationHelper helper, Bar viewModel)
  </code></pre>
  
  <p>I like this very much! I can directly access my viewModel in code, the code in the view makes sense and the helper object does not get in the way. I haven't seen this convention before and I guess it worked before because of the naming convention. Using a property called Model hinted at how to resolve the object. Without that property, it couldn't resolve it anymore. </p>
  
  <p>I would like to adopt this for other kinds of helpers that contain view-specific properties, like select-lists or other properties that I otherwise might have put in my ViewBag. Would you guys recommend this approach or will I run into trouble later on using this?</p>