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 5979271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:38:09+00:00 2026-05-22T21:38:09+00:00

I need to do a few db things and I would rather have extension

  • 0

I need to do a few db things and I would rather have extension methods in a separate file rather than having them all within the cshtml file.

But, I get the following error:

Compiler Error Message: CS0120: An
object reference is required for the
non-static field, method, or property
‘UserOperations.GetFirstName(string)’

Which points me to this line:

Line 165:                 <li><a href="@Href("myaccount/account.cshtml")">Hi, @UserOperations.GetFirstName(WebSecurity.CurrentUserId)</a></li>

The code I’m using is: (CSHTML)

@if(WebSecurity.IsAuthenticated)
                {
                  <li><a href="@Href("myaccount/account.cshtml")">Hi, @UserOperations.GetFirstName(WebSecurity.CurrentUserId.ToString())</a></li>
                }
                else
                {
                    <li><a href="@Href("myaccount/Login.cshtml")">My Account</a>

                <ul>
                  <li><a href="@Href("myaccount/Login.cshtml")">Sign In</a></li>
                    <li><a href="@Href("myaccount/Register.cshtml")" title="It's FREE!">Create Account</a></li>
                </ul>
              </li>
            }

And…: (UserOperations.CS)

using System;
using WebMatrix.WebData;
using WebMatrix.Data;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// User & Database-based operations in this file only.
/// </summary>
public class UserOperations
{
    public string GetFirstName(string CurrentUserID)
    {
        WebSecurity.InitializeDatabaseConnection("eee", "www", "www", "www", true);
        var database = Database.Open("OSF");
        var SelectQueryString = "SELECT FirstName FROM UserProfile WHERE FirstName = " + CurrentUserID;
        var result = database.Query(SelectQueryString);
        return result.ToString();
    }
}

I don’t get what the error is trying to say. I do this kinda stuff in C# Desktop apps all the time, I don’t understand how or what I’m doing wrong? Can someone please help?

Thank you!

  • 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-05-22T21:38:10+00:00Added an answer on May 22, 2026 at 9:38 pm

    You are not instantiating the class, so you would need to make it static.

    public static class UserOperations 
    {     
        public static string GetFirstName(string CurrentUserID)     
        { 
    

    More typically, though, you would have a User class that you would create an instance of in your controller, and pass that to your model. This will help you avoid doing discreet queries for each piece of information you need.

    You may want to investigate the Repository Pattern.

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

Sidebar

Related Questions

How do you store file permissions in a repository? A few files need to
I have a few models that need to have custom find conditions placed on
I have few asynchronous tasks running and I need to wait until at least
I have a few batch files I need to run frequently in developing a
I have various sorting methods that are all sorting the same 100,000 random number
I'm creating a user-based website. For each user, I'll need a few MySQL tables
I need to deploy a few files that were checked in sometime ago (can't
I need to do a few very simple URL manipulations in Java. Like get
I need to deploy a few .net dlls. They need to be put in
I need to read smallish (few MB at the most, UTF-8 encoded) XML files,

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.