Question

I am trying to do Jquery call on click of an element, on controller side i have this below, this is from Facebook C# mvc template.

 [FacebookAuthorize("email", "friends_birthday")]
    public async Task<ActionResult> GetFriends(FacebookContext context)
    {
        try
        {


        if (ModelState.IsValid)
        {
            var user = await context.Client.GetCurrentUserAsync<MyAppUser>();
            var friendsWithUpcomingBirthdays = user.Friends.Data.Take(100);
            user.Friends.Data = friendsWithUpcomingBirthdays.ToList();
            return PartialView("MyFriends", user);
        }

        return View("Error");
    }
    catch (Exception ex)
    {

        return View("Error");
    }

}

since i am trying to call using jquery inside a javascript file i tired using

@Html.Hidden("MyFriends", GlobalFacebookConfiguration.Configuration.AppUrl@Url.Action("GetFriends", "Home"))

and on my Jquery i do

var myUrl = $("#MyFriends").val();
    $.get(myUrl, function (data) {
        $('#detailsDiv').replaceWith(data);
    });

But i get error on my @Html.Hidden("MyFriends", GlobalFacebookConfiguration.Configuration.AppUrl@Url.Action("GetFriends", "Home")) saying ") expected ; expected" enter image description here

Any Ideas?

Was it helpful?

Solution

Try something like :

@Html.Hidden("MyFriends", GlobalFacebookConfiguration.Configuration.AppUrl + "/" + @Url.Action("GetFriends", "Home"))

OTHER TIPS

You shouldn't use Razor @Html helpers in a js file. Instead, add it to a cshtml file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top