I am trying to get the user model to work, but for some reason the values are not set. The code seems ligid when comparing it with the working code, but still it does not bind. I think this is some kind of trivial thing that I do not see.
Custom model:
public List<KeyValuePair<string, string>> MenuItems;
public IPrincipal CurrentUser = null;
public Foundation Foundation;
public class AdminClusterCreateModel : BaseViewModelAdmin
{
public Cluster Item;
public AdminClusterCreateModel()
{
Item = new Cluster();
}
}
The presentation form looks like this:
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Cluster</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Item.Active)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Item.Active)
@Html.ValidationMessageFor(model => model.Item.Active)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Item.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Item.Name)
@Html.ValidationMessageFor(model => model.Item.Name)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
And the controller:
[HttpPost]
public ActionResult Create(AdminClusterCreateModel model, FormCollection form)
{
if(ModelState.IsValid)
{
var test = form["Item.Name"];
UpdateModel(model);
}
return View(model);
}
Cluster on request
public partial class Cluster
{
public Cluster()
{
this.Team = new HashSet<Team>();
}
public long Id { get; set; }
public System.DateTime Created { get; set; }
public System.DateTime Modified { get; set; }
public bool Active { get; set; }
public long FoundationId { get; set; }
public string Name { get; set; }
public virtual Foundation Foundation { get; set; }
public virtual ICollection<Team> Team { get; set; }
}
source
share