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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:38:17+00:00 2026-05-22T15:38:17+00:00

I’m learning ASP.NET MVC 3 and trying to create a View with a single

  • 0

I’m learning ASP.NET MVC 3 and trying to create a View with a single form which is made up of multiple Models linked together by a foreign key. The end goal is to have the single form insert into all the database tables.

The problem is that I cannot figure out why when I right click to create the View that the form is not auto-generated in the cshtml file. Auto-generated code helps a lot since I have many tables that link together, and many fields which I must validate and insert. If it’s not possible to auto-generate the form, what is the most efficient/elegant way to get this done?

Here’s a simplification of what I have.

Model:

class Customer
{
    [Key]
    public UInt64 CustomerId { get; set; }

    [Required(ErrorMessage = "Name is required.")]
    [Display(Name = "Customer Name")]
    [MaxLength(50)]
    public string FullName { get; set; }
}

class CustomerAdditionalDetails1
{
    [ForeignKey("Customer")]
    public UInt64 CustomerId { get; set; }

    [Required(ErrorMessage = "This info is required.")]
    [Display(Name = "Customer Information")]
    [MaxLength(50)]
    public string SomeInfo { get; set; }
}

class CustomerAdditionalDetails2
{  // same foreign key as CustomerAddtionalDetails1, but with different properties
}

class CustomerAdditionalDetails3
{  // same foreign key as CustomerAddtionalDetails1, but with different properties
}

...

public class CustomerModel
{
    public Customer Customer { get; set; }
    public CustomerAdditionalDetails1 CustomerAdditionalDetails1 { get; set; }
    public CustomerAdditionalDetails2 CustomerAdditionalDetails2 { get; set; }
    public CustomerAdditionalDetails3 CustomerAdditionalDetails3 { get; set; }
    ...
}

Controller:

public ActionResult Submit()
{
    return View();
}

[HttpPost]
public ActionResult Submit(CustomerModel customer)
{
    return View();
}

Please 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-22T15:38:18+00:00Added an answer on May 22, 2026 at 3:38 pm

    When you generate the view, are you creating a strongly typed view based on CustomerModel? If you are then generating a view won’t output any values in the page because all your properties are references to other objects. You need actual value types contained in the model for the scaffolding to include them in the view automatically. That said you can always add them in the view yourself as per the example below.

    Also I notice in your controller that your GET method doesn’t return a model to the view to render. If you want to have a view generated based on the model then you need to pass the object that you want it to generate it for.

    @model MvcApplication3.Models.CustomerModel
    
    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>
    
    <fieldset>
        <legend>CustomerModel</legend>
    </fieldset>
    <ul>
    <li>@Model.Customer.FullName</li>
    <li>@Model.CustomerAdditionalDetails1.SomeInfo1</li>
    <li>@Model.CustomerAdditionalDetails2.SomeInfo2</li>
    </ul>
    <p>
        @Html.ActionLink("Edit", "Edit", new { /* id=Model.PrimaryKey */ }) |
        @Html.ActionLink("Back to List", "Index")
    </p>
    
    
    public class CustomerController : Controller
        {
            public ActionResult Index()
            {
                CustomerModel customerModel = new CustomerModel() 
                { 
                    Customer = new Customer()
                    {
                        FullName = "Dan"
                    },
                    CustomerAdditionalDetails1 = new CustomerAdditionalDetails1() 
                    { 
                        SomeInfo1 = "Somewhere1" 
                    },
                    CustomerAdditionalDetails2 = new CustomerAdditionalDetails2()
                    {
                        SomeInfo2 = "Somewhere2"
                    },
                    CustomerAdditionalDetails3 = new CustomerAdditionalDetails3()
                    {
                        SomeInfo3 = "Somewhere3"
                    }
                };
    
                return View(customerModel);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have text I am displaying in SIlverlight that is coming from a CMS
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.