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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:02:29+00:00 2026-06-04T20:02:29+00:00

I have this common CUser class public class CUser { public String Username {

  • 0

I have this common CUser class

public class CUser
{
    public String Username { get; set; }
    public String Password { get; set; }
}

Then I have this code on my client that uses RestSharp

    public void CreateUser()
    {
        RestRequest request = new RestRequest(Method.POST);
        request.RequestFormat = DataFormat.Json;
        request.Resource = "user/{cUser}";

        CUser user = new CUser
        {
            Username = "Foo",
            Password = "BarBaz"
        };

        request.AddParameter("cUser", user, ParameterType.UrlSegment);

        client.PostAsync<int>(request, (response, handler) =>
            {
                System.Diagnostics.Debug.WriteLine(response.StatusDescription);
                System.Diagnostics.Debug.WriteLine("id: " + response.Data);
            });
    }

And this http route in my global.asax

            routes.MapHttpRoute(
            name: "CreateUser",
            routeTemplate: "api/{controller}/{cUser}",
            defaults: new
                          {
                              controller = "User",
                              action = "CreateUser",
                              cUser = RouteParameter.Optional
                          });

And this servercode to handle it

    public int CreateUser(CUser cUser)
    {
        User user = new User(cUser);
        LoginManager manager = new LoginManager();
        return manager.CreateUser(user);
    }

But everytime I run it cUser’s values are null (Username and Password) so do I need to do something to restsharp to make it serialize it properly?

  • 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-04T20:02:30+00:00Added an answer on June 4, 2026 at 8:02 pm

    I think this is what you want:

    request.AddParameter("username", user.Username);
    request.AddParameter("password", user.Password);
    

    What you’re doing would result in cUser.ToString() being substituted for the {cUser} placeholder.

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

Sidebar

Related Questions

I have code like this: public bool Set(IEnumerable<WhiteForest.Common.Entities.Projections.RequestProjection> requests) { var documentSession = _documentStore.OpenSession();
I have this class: Public Class common Public Function NumbersOnlyEvent(ByVal CtrlName As String, ByVal
I have a web application that uses a library which resides in TOMCAT_HOME/common/lib. This
I have this interface: public interface Command<T> { T execute(String... args); } it works
I have this code in a common javascript file in my asp.net project. jQuery-Lint
I have a common code of serializing a class object in my 3-4 methods
I have this code inside http://www.mysite.local/js/site/functions.js : $.getScript('/js/common/jquery.jsonrpc.js', $.jsonRPC.setup({ endPoint: '/api/accounts', namespace: 'mynamespace' })
We have this common scenario where we have a method that performs some action
I have this code here, it is supposed to remove the common letters from
I have this scenario, which I think must be pretty common: class Parameter {

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.