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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:15:18+00:00 2026-05-18T03:15:18+00:00

Hey everyone, I am playing around with ASP.NET MVC and Entity Framework. I was

  • 0

Hey everyone, I am playing around with ASP.NET MVC and Entity Framework. I was wondering what is the best way to deal with passing around data from controllers to views and then back. I will explain a little better:

I have an action that is for creating a new “Receipt” object

        [Authorize]
    public ActionResult CreateReceipt(int id)
    {
           //I create the receipt object
            Receipt newReceipt = new Receipt();
           // assign some information about the owner of the receipt 
           // and the group that it belongs to
            newReceipt.Group = group;
            newReceipt.Owner = user;
            //send off to the view to be displayed
            return View(newReceipt);
    }

So I basically create a receipt and pre-fill in some information (including the authorized user and some group ID information) I can then send that to a view with all sorts of form elements that let the user fill in the other missing fields and submit so that a new receipt is added. This all works great if all the fields from the receipt object are being displayed on the form.

If I remove the form elements for things that the user shouldn’t be touching (such as the group number, the user id that the receipt belongs to, etc…) Then when I submit the form and pick it up in the controller:

        [HttpPost]
    [Authorize]
    public ActionResult CreateReceipt(Receipt receipt)
    {

        if (ModelState.IsValid)
        {
            using (EntityFrameworkEntities context = new EntityFrameworkEntities)
            {
                context.AddToReceipts(receipt);
                context.SaveChanges();
            }
            return RedirectToAction("Index");
        }

        return View(receipt);
    }

Then all that handy preloaded information that I filled in and sent to the view doesn’t come back with the post. I know I could place the UserID or the GroupID into a hidden field and then it makes it back with the POST, but that feels wrong. Technically someone could go in, change the hidden values and resubmit the post. I could then do checking to make sure that everything should be where it belongs, but that also feel like another trip to the database to get information that I already got once.

If anyone can elaborate a bit on what the standard way of passing data around from model to view to controller, that would be great. Thank you for your time and help!

  • 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-18T03:15:19+00:00Added an answer on May 18, 2026 at 3:15 am

    If you’re worried about someone monkeying with hidden field values to affect other records, pad the ID value and encrypt it in the hidden field, then decrypt on postback.

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

Sidebar

Related Questions

Hey everyone, I am trying to ( temporarily! ) do some ASP.NET and C#
Hey everyone, I was wondering if someone could point me in the right direction
Hey everyone. I'm fairly new to VB.NET and I'm looking to create a module
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey everyone, I am trying to run the following program, but am getting a
Hey everyone. I'm trying to make a swing GUI with a button and a
Hey everyone, I'm working on a PHP application that needs to parse a .tpl
Hey everyone... I'm not too familiar with PHP... but I have PHP code that
Hey everyone, I am working on parsing the PDF content stream to be able
Hey everyone, this is my first post up on StackOverflow! WOO! Anyhow, onto my

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.