Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:18:06+00:00 2026-06-02T19:18:06+00:00

When user clicks the link this method takes the user id and other data

  • 0

When user clicks the link this method takes the user id and other data and writes it to the database. I can’t seem to find a way to track what is the user id since the id is automatically generated.

I am using membership base separately from my base. In order to find userID I was trying to compare UserName strings. I get this error: “An unhandled exception was generated during the execution of the current web request.” Also “Cannot create an abstract class.”
Is there a better way to compare two strings form the two databases? Or is there a better way? This is my first time using lambda expressions.

I tried using Single() and First() instead of Where(), but I still get the same error.

[HttpPost]
public ActionResult AddToList(Review review, int id, HttpContextBase context)
    {
        try
        {
            if (ModelState.IsValid)
            {
                //User user = new User();
                //user.UserID = db.Users.Where(c => c.UserName == context.User.Identity.Name);
                User user = new User();
                Movie movie = db.Movies.Find(id);
                review.MovieID = movie.MovieID;

                string username = context.User.Identity.Name;
                user = (User)db.Users.Where(p => p.UserName.Equals(username));

                review.UserID = user.UserID;
                db.Reviews.Add(review);
                db.SaveChanges();
                return RedirectToAction("Index");
             };

        }
        catch (DataException)
        { 
            //Log the error (add a variable name after DataException)
            ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
        }
        return View(review);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:18:07+00:00Added an answer on June 2, 2026 at 7:18 pm

    you’re problem is likely this line:

    user = (User)db.Users.Where(p => p.UserName.Equals(username));
    

    the Where() extension method returns an IEnumerable, not a single instance, so your implicit cast will fail every time. what you’re looking for is either First() or FirstOrDefault(). First() will throw an exception if there is no match though, while FirstOrDefault()will return a null if no match is found. the line should be :

    user = db.Users.First(p => p.UserName.Equals(username));
    

    you probably have bigger problems than that, but this is the cause of your current error.

    EDIT

    upon further looking at your code, you’re asking for a HttpContextBase in your action result call. you never use it, and it’s probably the cause of the Cannot create an abstract class exception. remove that parameter and see if you get any different results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use case: user clicks the link on a webpage - boom! load of files
I have the following script that runs when a user clicks a link that
In a fictitious web application ... The user clicks a link The server starts
My app should render html, to answer when a user clicks ajax-link. My controller:
When the user clicks on a link to generate report I make an AJAX
I have noticed when user clicks on a link with, say middle button, or
Every time a user clicks on a link in a list view unordered list,
Here's the use case: A user clicks on a link that opens a window
I have got a module, where, when a user clicks on a link, I
When a user clicks on a button or link, I use the SimpleModal jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.