My model:
public class AdminPageModel
{
public int? JobID { get; set; }
[DisplayName("Description")]
public string Description { get; set; }
[DisplayName("Weight")]
public decimal Weight { get; set; }
public int ID { get; set; }
}
Form 1:
using (Html.BeginForm("EditTemplate", "Config", FormMethod.Post, new { @class = "form-horizontal" }))
{
for (var i = 0; i < Model.Count; i++)
{
<div class="form-group">
@if (Model[i].JobID != null)
{
@Html.LabelFor(m => m[i].Description)
@Html.TextBoxFor(m => m[i].Description)
@Html.LabelFor(m => m[i].Weight)
@Html.TextBoxFor(m => m[i].Weight)
@Html.HiddenFor(m => m[i].ID)
@Html.HiddenFor(m => m[i].JobID)
<br />@Html.ActionLink("Delete", "DeleteTemplate", new { id = @Model[i].ID, jobID = selectedJobID })
}
</div>
}
<input type="submit" value="Update" class="btn btn-success" id="editSubmit" />
}
Form 2:
using (Html.BeginForm("EditCompetency", "Config", FormMethod.Post, new { @class = "form-horizontal" }))
{
for (var i = 0; i < Model.Count; i++)
{
<div class="form-group">
@if (Model[i].JobID == null)
{
@Html.LabelFor(m => m[i].Description)
@Html.TextBoxFor(m => m[i].Description)
@Html.LabelFor(m => m[i].Weight)
@Html.TextBoxFor(m => m[i].Weight)
@Html.HiddenFor(m => m[i].ID)
@Html.HiddenFor(m => m[i].JobID)
<br />@Html.ActionLink("Delete", "DeleteCompentency", new { id = @Model[i].ID})
}
</div>
}
<input type="submit" value="Update" class="btn btn-success" id="editSubmit" />
}
Controllers:
[HttpPost]
public ActionResult EditCompetency(List<AdminPageModel> modelList)
{
// stuff
}
[HttpPost]
public ActionResult EditTemplate(List<AdminPageModel> modelList)
{
// stuff
}
Here's the issue. I have templates and competencies. I can add/delete all day long. Running into an issue when attempting to edit.
No issue at all with the templates, only with the competencies. If I add a competency and no template exists, the edit works just fine. But if a template exists when I try to edit a competency, the List<AdminPageModel> modelList
(the type that my view is strongly typed to) comes in as null. If I delete the template, I can edit the competency to my hearts content. I've spent a chunk of this morning spinning my gears on this.