ASP.NET MVC not rendering view

Viewed 1020

I have the following

NewsFeedController.cs

public class NewsFeedController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult TwitterCallback(string oauth_token, string oauth_verifier)
    {
        var requestToken = new OAuthRequestToken { Token = oauth_token };

        string Key = "";
        string Secret = "";

        try
        {
            TwitterService service = new TwitterService(Key, Secret);

            OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);

            service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);

            VerifyCredentialsOptions option = new VerifyCredentialsOptions();

            TwitterUser user = service.VerifyCredentials(option);
            String name = user.ScreenName;

            ViewData["user_name"] = name;
        }
        catch
        {
            throw;
        }
        return View();
    }
}

with the following

TwitterCallback.cshtml

@{
    ViewData["Title"] = "TwitterCallback";
}

<h2>Hello, @ViewData["user_name"]</h2>

RouteConfig.cs

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

My problem is that the NewsFeedController doesn't render anything. It executes TwitterCallback without throwing exception but it doesn't return any view. If I change the method type to String and return ViewData["user_name"], the correct name is displayed. Therefore, I think I have somehow declared the view the wrong way.

I just started getting my hands on with mvc so I apologise if this may sound like a beginner question.

Any help/tips would be greatly appreciated!

Project Structure:

Project Structure

This is what I get: (no error message, nothing)

enter image description here

EDIT: This is how the callback URL is called: (where TwitterAuth is a method in HomeController.cs and is called when the user clicks the login button)

public ActionResult TwitterAuth()
        {
            string Key = "";
            string Secret = "";

            TwitterService service = new TwitterService(Key, Secret);

            OAuthRequestToken requestToken = service.GetRequestToken("http://127.0.0.1:8080/NewsFeed/TwitterCallback");

            Uri uri = service.GetAuthenticationUrl(requestToken);

            return Redirect(uri.ToString());
        } 

If i just paste the redirect URL in my browser I get that: enter image description here

EDIT2: Thank you all for your help. I still don't understand why it didn't work in the first place (as Andrei was saying in the comments, it's not a .net problem) I changed my twitter library to tweetinvi and now it works.

0 Answers
Related