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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:44:20+00:00 2026-05-29T23:44:20+00:00

I have users fill out their profile information somewhere on my site using the

  • 0

I have users fill out their profile information somewhere on my site using the AspNetSqlProfileProvider that came with the IDE.

I allow my users to edit their profile at any time by going to the edit profile page where the form to edit their profile auto-populates. I currently do this by using ViewBag to send each individual part of a user’s profile from my controller to the view (address and city for example):

Controller get:

ViewBag.address = CustomProfile.GetUserProfile(User.Identity.Name).Address;
ViewBag.city = CustomProfile.GetUserProfile(User.Identity.Name).City;

View:

    <div class="editor-field">
        @Html.TextBox("Address", (string)ViewBag.address)
    </div>

    <div class="editor-field">
        @Html.TextBox("City", (string)ViewBag.city)
    </div>

Controller post:

    public ActionResult ChangeProfile( FormCollection favorites )
    {
        CustomProfile profile = CustomProfile.GetUserProfile();
        profile.Address = favorites["Address"];
        profile.City = favorites["City"];
        profile.Save();
        return RedirectToAction("Profile");
    }

The above works fine for editing profiles, it is very smooth from my user’s perspective (although, from reading questions/answers online it appears I should be using a ViewModel, not exactly sure how to make the transition – have been failing).

When my user’s go to ‘checkout’ from the website (they’ve been shopping), they are presented with a screen that allows them to input final information that allows them to make their purchase. Let’s call this the, “Order Page.” These details include name, address, credit card info, etc. Some of these pieces of information are the same as the information within the profile page of the website.

I want to be able to auto-populate some of the details in this Order Page (name, address) while leaving some of the fields blank (credit card – so the user has to fill these details in each time they visit the order page).

The way the Order page works is as the MVC Store Tutorial describes. When the Order Page is displayed it displays the form using:

@Html.EditorForModel()

Which is great and allows you to edit the details specified within the Order model and will allow for the data verification stuff (name is required, address is required, credit card has to be numbers, email is properly formatted, etc), but I cannot figure out how to populate specific fields within this Order Page with details from my user’s profile.

I have attempted building a new ViewModel that uses just the information contained within my profile, but I do not have a clear grasp of what is needed because I am not getting the end-result I am desiring.

I have considered using just the Order Model as my Profile information, but that is not sufficient because I want to have different information available in both.

I have considered using the Profile information as the Order Model, but I want my users to have the flexibility to store profile information separately from whatever information they use to actually place orders.

I think what I need to know specifically to fix my problem is how do I auto-populate specific fields while using “@Html.EditorForModel()” ?

Any other help with my overall situation would be great, I am very open to any advice that would simplify my flow (it feels like I am making it harder on myself than I need to, and I am at a point where collaboration would feel like a breath of fresh air).

  • 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-29T23:44:21+00:00Added an answer on May 29, 2026 at 11:44 pm

    I was able to follow only the first half of your question. It’s the one in which you have showed some code and the one with which I can help you. The second half was a complete mist for me.

    So when you want to design a view think of what fields this view needs to display/edit. And design a view model for it:

    public class ChangeProfileViewModel
    {
        [Required]
        public string Address { get; set; }
    
        [Required]
        public string City { get; set; }
    }
    

    and then have your GET controller action that is supposed to render this view populate the view model:

    public ActionResult ChangeProfile()
    {
        CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name);
        ChangeProfileViewModel model = new ChangeProfileViewModel
        {
            Address = profile.Address,
            City = profile.City
        };
        return View(model);
    }
    

    then you design the corresponding view which will be strongly typed to this view model:

    @model ChangeProfileViewModel
    @using (Html.BeginForm())
    {
        @Html.EditorForModel()
        <button type="submit">OK</button>
    }
    

    and finally you have a POST controller action that will handle the submission of this form:

    [HttpPost]
    public ActionResult ChangeProfile(ChangeProfileViewModel model)
    {
        if (!Model.IsValid)
        {
            // there were validation errors => redisplay the view
            return View(model);
        }
    
        // validation succeeded => process the results
        CustomProfile profile = CustomProfile.GetUserProfile();
        profile.Address = model.Address;
        profile.City = model.City;
        profile.Save();
        return RedirectToAction("Profile");
    }
    

    Now what we observe here is that in both our GET and POST actions we have repetitive mapping code between our domain model (CustomProfile) and our view model (ChangeProfileViewModel). To solve this issue I may recommend you using AutoMapper. It could simplify your GET action to:

    public ActionResult ChangeProfile()
    {
        CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name);
        ChangeProfileViewModel model = Mapper.Map<CustomProfile, ChangeProfileViewModel>(profile);
        return View(model);
    }
    

    or with a custom action filter to even:

    [AutoMap(typeof(CustomProfile), typeof(ChangeProfileViewModel))]
    public ActionResult ChangeProfile()
    {
        CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name);
        return View(profile);
    }
    

    and your POST action to:

    [HttpPost]
    public ActionResult ChangeProfile(ChangeProfileViewModel model)
    {
        if (!Model.IsValid)
        {
            // there were validation errors => redisplay the view
            return View(model);
        }
    
        // validation succeeded => process the results
        CustomProfile profile = CustomProfile.GetUserProfile();
        Mapper.Map<ChangeProfileViewModel, CustomProfile>(model, profile);
        profile.Save();
        return RedirectToAction("Profile");
    }
    

    What’s important to know about view models is that you should always use them for each view and design them in such a way so that they contain only the specific information that this view needs to handle. Leave to the mapping layer handle the conversion between your domain entities and your view models.

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

Sidebar

Related Questions

On my site, I have a form that users fill out to become a
I have a big form on my site. When the users fill it out
Okay all, I have a form that I want users to fill out. When
I have a form that I have users fill out and then it gets
I have a form that users fill out, and on the form there are
i have a form that users can fill out and i need the users
I have a form which users must fill out and submit. The controller action
i have a database fill with information of the users who use my webpage.
I have a form where my users can register to my site. They fill
I have a donation form which users fill out and I would like to

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.