Nashmár
Nashmár

Reputation: 392

jQuery AJAX show detail on click wrong redirecting

I have this script which is supposed to show details of MeetingCenter (by rendering partial view) on link click when I am on /Home/EmployeeDetails/EmployeeId. However it seems to redirect to /Home/EmployeeDetails/home/meetingcenterdetail/ instead.

Piece of View

<a class="LoadMCDetail" href="javascript:void(0)" data-assigned-id="@Model.MeetingCentre.MeetingCenterId">@Model.MeetingCenter.Name</a>
@section Scripts{
    <script type="text/javascript">
        $(function () {
            $(".LoadMCDetail").click(function () {
                $("#MCDetail").load("home/meetingcenterdetail/", {
                    id: $(this).data('assigned-id')
                });
            });
        })
    </script>
}

Piece of Home Controller

public async Task<IActionResult> EmployeeDetails(string id)
{
    return View(await _employeeRepository.GetItemAsync(id));
}

public async Task<IActionResult> MeetingCenterDetail(string id)
{
    return PartialView("_MeetingCenterDetailPartial", await _meetingCenterReposiotry.GetItemAsync(id));
}

Upvotes: 0

Views: 56

Answers (1)

Chad H
Chad H

Reputation: 594

Instead of

$("#MCDetail").load("home/meetingcenterdetail/", {
                id: $(this).data('assigned-id')
            });

Try:

$("#MCDetail").load("/home/meetingcenterdetail/", {
                    id: $(this).data('assigned-id')
                });

Basically I added a slash in front of home, which is root relative.

Upvotes: 1

Related Questions