In an MVC4 project im using a partial View thats using a ViewModel and has a GET Form on it. In the Controller action i expect the ViewModel object with some data. When this partial is placed on a normal (.cshtml) View, i recieve the data via the expected ViewModel object in the Controller action. But, When this partial is placed on another partial view, for some reason the ViewModel object in the controller action is empty. When i step through the creation of the HttpGet-form, the passed-in model is not empty, but when the GET controller action is called, the model is.
Anyone know the reason for this? Is this some MVC behavior i don't know about maybe? Thanks!
The Partial:
@model ViewModel
@if (Model != null)
{
using (Html.BeginForm("DoSomething", "Home", FormMethod.Get))
{
@Html.HiddenFor(m => m.Object)
<input id="btnSend" type="submit">
}
}
The Other Partial:
@using OtherViewModel.ViewModel
@Html.Partial("The Partial", Model.ViewModel, ViewData)
The View:
@Html.Partial("_TheOtherPartial", Model.OtherViewModel, new ViewDataDictionary(ViewData) {
TemplateInfo = new System.Web.Mvc.TemplateInfo { HtmlFieldPrefix = "prefix" }
})
The Controller
[HttpGet]
[AllowAnonymous]
public ActionResult DoSomething(ViewModel data)
{
}