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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:38:51+00:00 2026-05-26T07:38:51+00:00

I’m attempting to implement a Create action method for an ASP.NET MVC web application.

  • 0

I’m attempting to implement a “Create” action method for an ASP.NET MVC web application. I understand that there is a helper method for this and have successfully used it on other pages where there is a perfect 1:1 match between the form and the model. My question relates to a new page I am trying to add that needs to Post a combination of values captured in the form and values that are set in programatically. Here’s an example.

MembershipUser user = Membership.GetUser(User.Identity.Name);
Guid guid = (Guid)user.ProviderUserKey;
review.UserID = guid;
review.BusinessID = Convert.ToInt16(Request.Form["BusinessID"]);
review.Comments = Request.Form["Comments"];
review.Rating = Convert.ToInt16(Request.Form["Rating"]);
reviewsRepository.AddNewReview(review);
reviewsRepository.Save();

As you can see in this example, the UserID is defined in code and the rest of the values come from user inputs in the form.

Here’s the code for my AdNewReview and Save methods.

    public void AddNewReview(Review review)
    {
        db.Reviews.InsertOnSubmit(review);
    }

    //
    //Persist changes to database

    public void Save()
    {
        db.SubmitChanges();
    }

My questions are as follows:

  1. Can I still use the UpdateModel() helper method in this scenario? Please show an example if so. Or do all of the values have to come from the form for the reflection to work correctly?
  2. Even if there is a way to use the helper method in this scenario, I’d still like to learn to do it the manual way. What do I need to change about my code above to make it work?
  • 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-26T07:38:51+00:00Added an answer on May 26, 2026 at 7:38 am

    Yes, you can.

    UpdateModel just copies values from the Form to the object. You can still change them yourself.

    However, bear in mind that if the values also exist in the form, they will be overwritten, so you could call UpdateModel first.

    MembershipUser user = Membership.GetUser(User.Identity.Name);
    Guid guid = (Guid)user.ProviderUserKey;
    
    // Copy form values
    UpdateModel(review);
    
    // Overwrite custom values
    review.UserID = guid;
    reviewsRepository.AddNewReview(review);
    reviewsRepository.Save();
    

    Also be aware of security implications of using UpdateModel. A malicious user may add properties that weren’t in your form, and they will still be set on the model if they match.

    You can avoid this by using the overload that takes a string[] whitelist of properties to update, to ensure only the ones a user is allowed to modify are updated.

    MembershipUser user = Membership.GetUser(User.Identity.Name);
    Guid guid = (Guid)user.ProviderUserKey;
    
    // Copy form values
    UpdateModel(review, new string[] { "BusinessID", "Comments", "Rating" });
    
    // Overwrite custom values
    review.UserID = guid;
    reviewsRepository.AddNewReview(review);
    reviewsRepository.Save();
    

    If you’d like something more type-safe, you can also create an interface that contains just the properties to update, and pass that in as the generic type arg:

    public interface IReviewEditableFields
    {
        int BusinessID;
        string Comments;
        int Rating;
    }
    
    // This will only update the BusinessID, Comments and Rating properties
    UpdateModel<IReviewEditableFields>(review);
    

    Edit:

    I was just searching for a little more info on this, and found this post:

    ASP.NET MVC UpdateModel vulnerable to hacking?

    It seems that you can also whitelist properties on the class, which seems a better place for maintainability:

    [Bind(Include="MyProp1,MyProp2,MyProp3")]
    public partial class MyEntity { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT

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.