当我从 PartialView 中取出单击操作 jquery 时,代码停止工作:
局部视图:
@model Heelp.ViewModels.CategoryGetAllBySearchListViewModel
<p class="float-left margin-top align-left"><span>Encontrámos <em><a href="#">@Model.TotalSearchCount</a></em> resultados nas categorias:</span></p>
<div class="clear-both">
<div id="searchResultsList" class="float-left">
<ul>
@foreach (var item in Model.CategoryGetAllBySearch)
{
<li>
@Html.ActionLink(
String.Format("{0} {1} ver »", item.SearchCount, item.Name),
MVC.Company.GetAllByCategory(item.Id, Model.Search, Model.Location, Model.IsCenterFromUser, Model.CenterLng, Model.CenterLat, Model.SearchRadius),
new { id = "getCompanies" })
</li>
}
</ul>
</div>
</div>
<script>
$("#getCompanies").on("click", function()
{
$.ajax({
url: this.href,
cache: false,
success: function (result) {
companyGetAllByCategoryOnSuccess(result);
}
});
return false;
});
</script>
如果我把脚本代码放在一个外部的JS文件中,代码不起作用,为什么?
谢谢。