简体   繁体   中英

Bind Action not working outside of the partialview

When I take away from the PartialView the click action jquery, the code stop working:

Partial View:

@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>

If I put the script code in an external JS file, the code don't work, why?

Thanks.

I removed all the validation and unobtrusive js files from the project and reload them from NuGet, and everything got solved.

Thanks for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM