So I load this:
$('#categories').load("/Category/GetCats");
from this controller
public ActionResult GetCats()
{
var model = db.Cats
.Where(c => c.user_id == 5);
//var query = from c in db.Cats where c.user_id == 4 orderby c.catId select c;
//var i = query.Count();
//var results = query;
return PartialView("_PartialGetCats", model);
}
to render this view
@foreach (var item in Model)
{
<tr>
<td data-id="@item.catId">@item.item_name</td>
</tr>
}
The categories show but this function
$('#categories tr').on("click", function () {
var requestpage = "/Item/Partial?id=" + $(this).data("id");
alert(requestpage);
$.get(requestpage, function (result) {
$("#results").html(result);
});
or any other jquery functions do not recognize the $('#categories tr)
. It will however recognize $('#categories')
. I tested by removing the load()
and hardocding this
$('#categories').html('<tr data-id="5"><td>new data</td></tr>');
and it works. Whats going on?
EDIT: full Index.cshtml view
@{
ViewBag.Title = "Home Page";
}
<div id="categories">
</div>
<div id="results">
</div>
<div id="descrip">
</div>