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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:40:07+00:00 2026-06-13T09:40:07+00:00

So I have a UserDisplayModel with the default MembershipUser as a property, and I’m

  • 0

So I have a UserDisplayModel with the default MembershipUser as a property, and I’m trying to pass the whole view model to the controller, but for some reason the MembershipUser property and likely the whole model gets lost.

I found this out because I get a No parameterless constructor defined for this object error unless I manually instantiate the MembershipUser inside the display model constructor). Meaning the second action (posted below) tried to make a new UserDisplayModel and errors because MembershipUser has no default constructor.

Here’s my code:

Model

public class UserDisplayModel
{
    public MembershipUser User { get; set; }

    public UserDisplayModel(string id)
    {
        this.User = Membership.GetUser(id);
    }
}

Actions

public ActionResult Delete(string id)
{
    UserDisplayModel model = new UserDisplayModel(id);

    return PartialView("Delete", model);
}

[HttpPost]
public ActionResult Delete(UserDisplayModel model)
{
    Membership.DeleteUser(model.User.UserName);
}

View

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcWebRole1.Models.UserDisplayModel>" %>

<p>Are you sure you want to delete the following user?</p>

<h2><%: Model.User.UserName%></h2>

<% using (Html.BeginForm()) { %>
    <p>
        <%: Html.HiddenFor(model => model.User.UserName)%>
        <input type="submit" value="Delete" class="small alert button" />
        <input type="button" value="Cancel" class="small secondary button cancel-action" />
    </p>
<% } %>

Is it possible to have this work, or does asp.net just not like having models inside models? Or did I just miss something silly?

  • 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-13T09:40:08+00:00Added an answer on June 13, 2026 at 9:40 am

    The error:

    No parameterless constructor defined for this object

    Is caused by

    [HttpPost]
    public ActionResult Delete(UserDisplayModel model)
    {
        Membership.DeleteUser(model.User.UserName);
    }
    

    As UserDisplayModel has no parameterless constructor for MVC to instantiate. It only has the constructor:

    public UserDisplayModel(string id)
    {
        this.User = Membership.GetUser(id);
    }
    

    I would probably changed the method too look like:

    [HttpPost]
    public ActionResult Delete(string userName)
    {
        Membership.DeleteUser(userName);
    }
    

    Or to be a little more MVC

    public class DeleteUserModel
    {
        public DeleteUser User { get; set; }
    
        public class DeleteUser
        {
            public string Username { get; set; }
        }
    }
    
    [HttpPost]
    public ActionResult Delete(DeleteUserModel model)
    {
        Membership.DeleteUser(model.User.UserName);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have one Doubt In MVC Architecture we can able to pass data from Controller
Have deployed numerous report parts which reference the same view however one of them
Have a painfully simple blog Post creator, and I'm trying to check if the
have a nice day. I got problem when trying to create an image from
Have a RESTful web-serice with Facade layer, Service layer and Dao layer. Trying to
Have a spreadsheet where the ordering of the worksheets may arbitrarily change, but not
have been trying couple of hours now to make my iphone app universal. The
Have some code: using (var ctx = new testDataContext()) { var options = new
have some headers like: HTTP/1.1 100 Continue HTTP/1.1 302 Found HTTP/1.1 200 OK HTTP/1.1
Have searched for the answer but no joy, so here goes... I'm working on

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.