I'm trying to pass data from my controller to a partial view using ViewData but it's not working correctly.
code in controller
public PartialViewResult PartFace()
{
string message = "You are not connected to Facebook";
string name = "";
string appid = ConfigurationManager.AppSettings["AppID"];
FacebookConnect fbConnect = new FacebookConnect();
if (fbConnect.IsConnected)
{
message = "You are connected to Facebook";
string token = fbConnect.AccessToken;
token = HttpUtility.UrlDecode(token);
Facebook.FacebookAPI api = new Facebook.FacebookAPI(token);
JSONObject me = api.Get("/" + fbConnect.UserID);
}
ViewData["Message"] = message;
ViewData["AppID"] = ConfigurationManager.AppSettings["AppID"];
ViewData["Name"] = name;
return PartialView();
}
code in partial view
<h2><%: ViewData["AppID"]%></h2>
<% if (!string.IsNullOrEmpty((string)ViewData["Name"])) { %>
<h2>Hello, <%: (string)ViewData["Name"]%> </h2>
<% } %>
<p>
<fb:profile-pic uid="loggedinuser" facebook-logo="true" linked="false"></fb:profile-pic>
<fb:login-button autologoutlink='true' onlogin='window.location.reload()' perms='read_stream,publish_stream,read_friendlists,user_activities'></fb:login-button>
</p>
<div id="fb-root"></div>
<script type='text/javascript'>
window.fbAsyncInit = function () {
FB.init({ appId: '<%= ViewData["AppID"] %>', status: true, cookie: true,
xfbml: true
});
};
(function () {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());
</script>
code to call this partial in master page
<% Html.RenderPartial("~/Views/Home/PartFace.ascx"); %>