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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:39:50+00:00 2026-06-17T16:39:50+00:00

I have a webforms project and I’m using the new Model Binding on ASP.NET

  • 0

I have a webforms project and I’m using the new Model Binding on ASP.NET 4.5. I have a strongly typed FormView on my page that contains a DropDownList that will allow the user to select a related entity (think Product -> Category).

Is there a way to set this up so that, on my InsertMethod, I can get direct access to the related entity (Product.Category, for example)? I need to check some validation rules on the related entities, and the only way I found to do that was to set up my DropDownList to return the Id of the related record, and then fetch it from the database. That seems rather inefficient.

Edit: Damn, no one huh!? Well, that’s what you get for being an early adopter of new technologies! 😀

  • 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-17T16:39:51+00:00Added an answer on June 17, 2026 at 4:39 pm

    I had the same issue on MVC, the best solution I have found was to use the ForeignKey data annotation on my model, this way I could insert only the related object’s ID and retrieve the object later. Here’s an example:

    public class Product {
        public int ProductId { get; set; }
        public string Name { get; set; }
        // Add this field so I can add the entity to the database using 
        // category id only, no need to instantiate the object
        public int CategoryId { get; set; }
    
        // Map this reference to the field above using the ForeignKey annotation
        [ForeignKey("CategoryId")]
        public virtual Category Category { get; set; }
    }
    
    public class Category {
        public int CategoryId { get; set; }
        public string Name { get; set; }
    }
    

    Now, it’s been ages since I last used WebForms so I don’t really know how to bind the categories list to the DropDownList, maybe something like this:

    <asp:DropDownList ID="CategoryId" SelectMethod="GetCategories" runat="server" />
    

    And maybe when you get your product back on your Create or Update method, it will come with the CategoryId property properly attributed, and then all you’ll have to do is save the EF’s context. Good luck.

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

Sidebar

Related Questions

I have a hybrid ASP.NET WebForms/MVC project. In my Master Page, I have a
I have an ASP.NET 3.5 webforms project written in VB that involves a multi-table
I have an ASP.NET WebForms project with N-Layers using Entity Framework 5. I have
I have an html file in my asp.net webforms project that people can download
I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the
I have an ASP.NET project (VS2008 on Windows 7 with either webforms, MVC1, or
I have a ASP.NET Webforms application that is being used with Motorola Tablets (Android
My project is in Asp.Net Webforms using C#. On one of my web pages,
I have a pretty big web application that I created last year using ASP.NET
I have ASP.NET WebForms project with online player. When i click play player asks

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.