ASP.NET MVC not rendering

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 NewsFeedController

it doesn't display anything. It executes TwitterCallback

without throwing exceptions but returns no view. If I change the type of the method to String and return the ViewData["user_name"]

correct name is displayed. Therefore, I think that I somehow proclaimed the point of view in the wrong way.

I just started chatting with mvc, so I apologize if this might sound like a beginner's question.

Any help / advice 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 into my browser, I get this: enter image description here

EDIT2: Thanks everyone for your help. I still don't understand why it didn't work in the first place (as Andrew said in the comments, this is not a .net issue). I changed my twitter library to tweetinvi and now it works.

+3
c # asp.net razor asp.net-mvc-4


source to share


No one has answered this question yet

Check out similar questions:

818
ASP.NET Web Site or ASP.NET Web Application?
799
ASP.NET MVC 3.0 File Upload
637
How to import namespace in Razor view page?
611
How do you handle multiple submit buttons in ASP.NET MVC Framework?
559
ASP.NET MVC - setting custom IIdentity or IPrincipal
537
How do I create a dropdown from an enum in ASP.NET MVC?
481
Compile views in ASP.NET MVC
324
ASP Engine MVC View Engine Comparison
239
ASP.NET MVC Razor no coding
1
handle url in asp.net mvc of invalid characters



All Articles
Loading...
X
Show
Funny
Dev
Pics