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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:44:01+00:00 2026-06-09T21:44:01+00:00

I am trying to let a user create an object and save it to

  • 0

I am trying to let a user create an object and save it to the database. I have scaffolded it all correctly etc and have modified my control to the following:

    Function Create(id As Integer) As ViewResult
        ViewBag.id = id
        Dim job As Job = New Job
        job.CustomerId = id
        job.JobAmount = 0
        job.JobDate = Date.Now()
        job.JobStatus = "Active"
        Return View(job)
    End Function

This then returns the following view:

        @ModelType Laundry.Job

        @Code
            ViewData("Title") = "Create"
        End Code

        <h2>Create</h2>

        <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

        @Using Html.BeginForm()
            @Html.ValidationSummary(True)
            @<fieldset>
                <legend>Job</legend>

                <div class="editor-label">
                    @Html.LabelFor(Function(model) model.JobDate)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(Function(model) model.JobDate)
                    @Html.ValidationMessageFor(Function(model) model.JobDate)
                </div>

                <div class="editor-label">
                    @Html.LabelFor(Function(model) model.BillId)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(Function(model) model.BillId)
                    @Html.ValidationMessageFor(Function(model) model.BillId)
                </div>

                <div class="editor-label">
                    @Html.LabelFor(Function(model) model.CustomerId)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(Function(model) model.CustomerId)
                    @Html.ValidationMessageFor(Function(model) model.CustomerId)
                </div>

                <div class="editor-label">
                    @Html.LabelFor(Function(model) model.JobStatus)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(Function(model) model.JobStatus)
                    @Html.ValidationMessageFor(Function(model) model.JobStatus)
                </div>

                <p>
                    <input type="submit" value="Create" />
                </p>
            </fieldset>
        End Using

        <div>
            @Html.ActionLink("Back to List", "Index")
        </div>

I created a instance of job and passed it through the controller to the view in order to default certain values. Specifically I need to create a job object with the id passed to the controller but I do not want the user to be able to edit this id (they should not see this). I thought that if I simply deleted the following from my view:

                <div class="editor-label">
                    @Html.LabelFor(Function(model) model.CustomerId)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(Function(model) model.CustomerId)
                    @Html.ValidationMessageFor(Function(model) model.CustomerId)
                </div>

The object would still save with the customerId I set in my controller however it seems if I delete this code when it saves it saves the customerid as 0 and when its there it works correctly but the user can see and edit it.

Am I doing this correctly?

  • 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-09T21:44:03+00:00Added an answer on June 9, 2026 at 9:44 pm

    I do not want the user to be able to edit this id (they should not see this)

    Use @Html.HiddenFor(Function(model) model.CustomerId) for this. It will persist the value from view to controller, but not be visible to the user.

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

Sidebar

Related Questions

All, I am trying to create a table to receive user inputs (UGC). This
I'm trying to let the user create either a file or a folder. So
I'm trying to create a list application that will let a user inputs an
Following is my piece of code in which I am trying to create database
I'm trying to let a user "make his own service". most direct method I
Let me first explain what's I'm trying to do. So I have a entity
I am trying to create a csv file of some data. I have wrote
I'm trying to create a log when an authenticated user creates a new session,
I am trying to create a dynamic UI using UpdatePanel of AJAX toolkit. Let
So I've got a control that has all different user inputs (comboBox, textBox, DatePicker,

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.