I am trying to add a textboxes control dymically using steven anderson's BeginCollectionItem. I follwed the example from his blog here for a start.
However, when i click the add button, my control is added to a new fresh window. Moreover , my form is bind to strongly typed model and my submit button works on stick. But since i added the control from his tutorial, my submit button is not submitting to my controller. Below is my view.
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
<script src="@Url.Content("~/Content/js/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
<script type="text/javascript">
$("#addItem").click(function () {
$.ajax({
url: this.href,
cache: false,
success: function (html) { $("#new-recipeingredients").append(html); }
});
return false;
});
</script>
@using (Html.BeginForm("SaveJob", "Employer", FormMethod.Post, new { @class = "form", @style = " border-top: none; " }))
{
...
<fieldset>
<legend>Job Requirement</legend>
<div class="new-recipeingredients">
@foreach(var item in Model.JobRequirement)
{
@Html.EditorFor(m => item)
}
</div>
<div style="padding: 10px 0px 10px 0px">
@Html.ActionLink("Add another...", "GetNewRecipeIngredient", null, new { id = "addItem" })
</div>
</fieldset>
}
and my controller
public ViewResult GetNewRecipeIngredient()
{
return View("~/Views/Shared/EditorTemplates/JobRequirement.cshtml", new JobRequirement());
}
When i click the addanother, it calls the GetNewRecipeIngredient controller and add a new textbox on a fresh window. I was expecting it right on top of my link add another. I am suspecting my JQuery code and i am not able to understand clear. Any help would appreciated.