I like how MVC 4 generates the views with the HtmlHelpers already defined:
<div class="editor-label">
@Html.LabelFor(model => model.PartId)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.PartId)
@Html.ValidationMessageFor(model => model.PartId)
</div>
But for one field I added a jQuery autocomplete and now the textbox has taken the form of a standard input field:
<div class="editor-label">
@Html.LabelFor(model => model.PartId)
</div>
<div class="editor-field">
<input type="text" id="parts" name="parts" />
</div>
When I Create the object (save the form) the Parts field is not brought in as a part of the new object. How can I pair this field up with the other auto generated HTML Helpers so it saves correctly? Here's my controller for reference however I'm hoping this can be accomplished in the page itself:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Part part)
{
if (ModelState.IsValid)
{
db.SaveChanges();
return RedirectToAction("Index");
}
return View(part);
}
The Part class, which is a child object on the form. The user will key in the MatchCode into the form but the page needs to save the Part object:
public partial class Part
{
public Part()
{
this.Counts1 = new HashSet<Count>();
}
public System.Guid Id { get; set; }
public string PartNumber { get; set; }
public string Matchcode { get; set; }
public string Unit { get; set; }
public virtual ICollection<Count> Counts1 { get; set; }
}
The Count class is the main Parent class:
public partial class Count
{
public System.Guid Id { get; set; }
public Nullable<System.Guid> LocationId { get; set; }
public Nullable<System.Guid> PartId { get; set; }
public Nullable<System.Guid> UnitId { get; set; }
public string DocumentNumber { get; set; }
public virtual Location Location { get; set; }
public virtual Part Part { get; set; }
public virtual Unit Unit { get; set; }
}
Partclass please?partstextbox meant to map to?nameattribute, then (instead of "parts").