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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:35:47+00:00 2026-06-09T18:35:47+00:00

I am trying to set a default value for the scaffold create view that

  • 0

I am trying to set a default value for the scaffold create view that MVC created for me. I have tried creating an instance of the model and passing it to the view but its throwing errors.

  Function Create(id As Integer) As ViewResult
        Dim job As Job
        job.CustomerId = id


        Return View(job)
    End Function

How would I get my create view to be prepopulated with the id in the parameter using the following view so when a new Job is created it is automatically created with that customer id. My view is below:

        @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.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.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.JobStatus)
                </div>
                <div class="editor-field">
                    @Html.EditorFor(Function(model) model.JobStatus)
                    @Html.ValidationMessageFor(Function(model) model.JobStatus)
                </div>

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

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

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

I don’t necessarily even need to show the customer id on the form but that new object needs to be created with the parameter passed to the controller and the rest of the info the user chooses.

  • 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-09T18:35:48+00:00Added an answer on June 9, 2026 at 6:35 pm

    Method 1 : If you want to show the customerId, then you can use the following code…

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

    This way, the CustomerId will be displayed, user cannot change it and when postback is done, this value is still present as a part of the model.

    Method 2 : If you dont want to display, but still use it for the above purpose, then use the code written below…

    <div class="editor-label">
     @Html.HiddenFor(Function(model) model.CustomerId)
    </div>
    

    Hope this is what you wanted.

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

Sidebar

Related Questions

I have a dataset that i am trying to set the default value as
I’m creating a TextView dymacally and trying to set a default value that is
I'm trying to set a default value in an instance variable. I'm doing: module
I'm trying to set a default value for several inputs at once, removing that
I'm trying to set a default value for a search field. The idea is
I am trying to set a number of Enums to default value I am
I am trying to set some default inherited permissions to a directory that will
I'm trying to set the default value for a Content Taxonomy field in a
I'm trying to change the default value of a foreignkey-formfield to set a Value
I am trying to drop the default value on a bit column, I have

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.