Im trying to make an asp.net mvc View with 2 PartialViews who get their informations by an ajax call with javascript.
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="form-group">
<label class="col-md-2 control-label"></label>
<div class="col-md-2">
<input id="CategoryName" class="form-control" />
<span class="text-danger"></span>
</div>
</div>
<div class="addbutton">
<input id="AddCatButton" type="button" class="btn btn-default custombtn" value="asd" />
</div>
</div>
<div class="row">
<div id="MasterContainer">
@Html.PartialFor("_Categories", Model.Categories, "Categories")
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-2 control-label"></label>
<div class="col-md-2">
<input id="CategoryItemName" class="form-control" />
<span class="text-danger"></span>
</div>
<div class="addbutton">
<input id="AddItemButton" type="button" class="btn btn-default custombtn" value="asd" />
</div>
</div>
<div id="DetailContainer">
@*Contentn of the Detailpage*@
</div>
</div>
</div>
everythings is working fine i can name and add a new Category the Partialview will "refresh" and then the scripts stop working.
ive included them in the _Layout.cshtml
The script calls the Controller and give back an PartialView("_Categories",model)
with every category in the database and also a second method gives back every item of a category but the script stopped working until i reload the whole page.
ive tried it to include the scripts on each partialview but then when i created a new category it creates 2,4,8,16,and so on Do I habe to include the script somewhere elöse or what is the solution.
The Javascript is one script with 3 Methods in it
$("#CatList li").on('click', function () {
// Shows all items in a category and refresh the itemlist partialview
});
$("#AddItemButton li").on('click', function () {
// Adding an item to the selected Category
// and refreshes the itemlist partialview
});
$("#AddCatButton li").on('click', function () {
// add a Category and refresh the category partialview
});