I have an ASP.NET MVC app that I'm building and I cannot figure out why the model being posted back is always null.
cshtml:
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.HiddenFor(model => model.TotalItemCategoryId, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Label, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Label, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Label, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Value, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Value, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Value, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.HiddenFor(model => model.Quantity, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="form-group">
@Html.HiddenFor(model => model.QuoteId, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="form-group">
@Html.HiddenFor(model => model.TotalTemplateId, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div class="form-group">
@Html.HiddenFor(model => model.AllowDataEntry,new{@readonly="readonly"})
</div>
<div class="form-group">
@Html.HiddenFor(model => model.IsMiscellaneous)
</div>
I have looked at the form and all of the fields are there with the correct values when posting. just when it gets to the controller it is always null. Can someone please help me figure this out.
Model class:
public class TotalItemValue:IEntity
{
public int Id { get; set; }
public int? TotalItemCategoryId { get; set; }
[StringLength(125)]
public string Label { get; set; }
public decimal? Value { get; set; }
public int? Quantity { get; set; }
public int QuoteId { get; set; }
public int? TotalTemplateId { get; set; }
public bool AllowDataEntry { get; set; }
public bool IsMiscellaneous { get; set; }
public TotalItemCategory TotalItemCategory { get; set; }
public TotalTemplate TotalTemplate { get; set; }
}
Controller:
public ActionResult CreateMiscellaneousItem(int quoteId)
{
TotalItemValue totalItemValue = _expressionTotalService.CreateMiscellaneousItem(quoteId);
return View(totalItemValue);
}
[HttpPost]
public ActionResult CreateMiscellaneousItem( TotalItemValue value)
{
_expressionTotalService.SaveMiscellaneousItem(value);
return RedirectToAction("Totals", new{quoteId=value.QuoteId});
}