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

  • Home
  • SEARCH
  • 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 6885501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:38:33+00:00 2026-05-27T05:38:33+00:00

I’m new at MVC and can’t get this to work. I basically have a

  • 0

I’m new at MVC and can’t get this to work. I basically have a Users class, a UserRepository, and a IUser interface.

This is my code:

public class Users
{

public string UserName { get; set; }
public string Department { get; set; }
public string UserType { get; set; }


}

 public class UsersRepository : TimeAttendanceMVC.Models.IUsers
{

    public Users Return_UserName_Dept()
    {
        Users U = new Users();
        List<Users> LoggedInUser = new List<Users>();

        U.UserName = "TestUser";
        U.Department = "Finance";
        U.UserType = "Administrator";

        LoggedInUser.Add(U);

        //string json = JsonConvert.SerializeObject(LoggedInUser, Formatting.Indented);
        //return json;

        return Json(LoggedInUser.ToArray(), JsonRequestBehavior.AllowGet);

    }


}

namespace TimeAttendanceMVC.Models
{
  public  class IUsers
    {
      List<Users> Return_UserName_Dept();

    }
}

There are a few errors that I get. In UsersRepository.cs where i’m returning Json, the error says that “The name Json does not exist in the current context”. The error from IUsers.cs is that “Return_UserName_Dept() must declare a body because it is not marked abstract…”.

Can anybody please help me with this. I just don’t know how this is supposed to work and i’m trying to learn MVC by working on this application. It’s actually the FullCalendar application found here – link to FullCalendar. I’m trying to turn it into an MVC application.


EDIT:

Maybe I need to do this:

public JsonResult Return_UserName_Dept()

instead of public Users Return_UserName_Dept()

  • 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-27T05:38:34+00:00Added an answer on May 27, 2026 at 5:38 am

    You should be doing this on your controller in some method which returns a json action (jsonresult). The repository should be returning your data only and all the operations you need to do, whether you’re converting data to json or any other logic should happen at the controller or at some helper class which would be called by the controller..

    Edit:

    In order to have a method which returns a JsonResult, you need to have a reference to System.Web.Mvc.ActionResult and since the repository is usually at the model, you won’t have this reference.. another thing is that you might be breaking your design the logic should be available at the controller for what you want

    Edit 2:

    The code below is from an old post you can see here. Note how the action PopulateDetails gets the user object from the repository and that’s all the repository does.. the actual logic is happening inside this method, such as populate the rest of the UserModel class, and then it returns the JsonResult:

    public JsonResult PopulateDetails(UserModel model)
    {
        UserResultModel userResultModel = new UserResultModel();
        if (String.IsNullOrEmpty(model.UserId))
        {
            userResultModel.Message = "UserId can not be blank";
            return Json(userResultModel);
        }
    
        User user = _userRepository.GetUser(model.UserId);
    
        if (user == null)
        {
            userResultModel.Message = String.Format("No UserId found for {0}", model.UserId);
            return Json(userResultModel);
        }
    
        userResultModel.LastName = user.LastName;
        userResultModel.FirstName = user.FirstName;
        userResultModel.Message = String.Empty; //success message is empty in this case
    
        return Json(userResultModel);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6

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.