I am creating a dynamic control by calling partial view.
When I change the value of dropdown at first time it works fine. But when I change the value of dropdown at second or more time i get replication of controls the number of times.
The jquery i used to append the division is:
<script type="text/javascript">
$("#addItem").live('click', function (e) {
e.preventDefault();
// $("#mydiv").html("");
$.ajax({
url: this.href,
type: "Get",
data: $(this).serialize(),
success: function (srcc) {
$("#mydiv").append(srcc);
}
});
return false;
});
</script>
and my controller look like :
[HttpGet]
public ActionResult BlankEditorRow()
{
TempData["PassedDivision"] = extract.getDivision();
TempData["Country"] = extract.getCountry();
return PartialView("ViewUserControl1");
}
The code for actionlink is:
@Html.ActionLink("Add another", "BlankEditorRow", "HREduInformation", new { id = "addItem" })
Where am I going wrong?Thankx for the help.
If your script tag is in the markup for the partial view, look at the rendered html in a browser and make sure that script is not being duplicated. Your javascript code is not wrapped in a function, so as soon as the script is loaded by your browser, it is executed.