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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:19:23+00:00 2026-06-04T22:19:23+00:00

i have a parent child situation with for example my user class and my

  • 0

i have a parent child situation with for example my user class and my userwork child class (Entity framework scaffolded classes). i used the controller wizard to scaffold CRUD methods and views. it scaffolded two Create method’s, the Get and the httpPost methods.

In a normal scenario i would want to be passing in the user’s id into the get so that it would be passed into the model which is being populated in html.beginform() section and then it would subsequently be passed into thepost.

I am unsure what is the correct method to do this? I have modified the Get as below

public ActionResult Create(int id)
 {
     this.ViewData.Add("id", id);
     return View();
 }

and the Create.shtml as below

@model UserWork

@{
    ViewBag.Title = "Create";
    int id = (int)ViewData["id"];
}

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

@using (Html.BeginForm(routeValues:new {user_id = @id})) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Userwork</legend>

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

(i left the scaffolded user_id fields as editable so i could test seeing them prepopulated when the form loads) which the form loads it doesnt have my id value in the fields, Is this the correct method of achieving this?

Cheers
Tim

  • 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-04T22:19:25+00:00Added an answer on June 4, 2026 at 10:19 pm

    So my initial question raised several other questions about my understanding of MVC and routing. i established that if i pass one parameter as an integer to the route in the form

    http://mydomain/controller/myaction/123 
    

    if my action method is in the form

    public ActionResult Create(int id)
            {}
    

    everything is cool but if its in the form

     public ActionResult Create(int user_id)
            {}
    

    then i was getting an exception that the required parameter user_id wasnt populated.
    I added an additional mapping as below and this seems to be correctly populating the view.

    routes.MapRoute("Create", "{controller}/Create/{user_id}",new {action = "Create"});
    

    I decided not to instantiate the model and pass it into the view as using the route above it passes the userid into the model’s user_id field correctly.

    Cheers
    Tim

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

Sidebar

Related Questions

I use Entity Framework 4 and I have parent - child relation with Cascade
In a situation where you have a parent class which has one child class,
I have a simple parent-child situation where the parent can have multiple children. The
I have a Parent/Child object/mapping as follows: class Parent { int Id; string name;
I have a parent and child class that both need to implement IDisposable .
I have two classes: Parent and Child , mapped one-to-many with relationship owned by
I have the following situation in my python code: class Parent(object): def run(self): print
I have this situation where I have a parent child relationship between two sets
I have a Parent entity with a Child entity in a ManyToOne relationship: @Entity
I have parent/child relationship set up via Node Reference. A Child record can 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.