Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
3
Answers
How to show ddl in mvc VM
Sajid Hussain
7y
741
1
Reply
I have following two tables.
CREATE
TABLE
[dbo].[CompanyProduct](
[ID] [
int
] IDENTITY(1,1)
NOT
NULL
,
[StockName] [nvarchar](50)
NOT
NULL
,
[CompanyID] [
int
]
NOT
NULL
,
[CreatedDate] [datetime]
NOT
NULL
,
[CreatedByID] [
int
]
NOT
NULL
,
[StockDetail] [nvarchar](100)
NULL
,
CONSTRAINT
[PK_CompanyProduct]
PRIMARY
KEY
CLUSTERED
(
[ID]
ASC
)
WITH
(PAD_INDEX =
OFF
, STATISTICS_NORECOMPUTE =
OFF
, IGNORE_DUP_KEY =
OFF
, ALLOW_ROW_LOCKS =
ON
, ALLOW_PAGE_LOCKS =
ON
)
ON
[
PRIMARY
]
)
ON
[
PRIMARY
]
GO
ALTER
TABLE
[dbo].[CompanyProduct]
WITH
CHECK
ADD
CONSTRAINT
[FK_CompanyProduct_TPSCompany]
FOREIGN
KEY
([CompanyID])
REFERENCES
[dbo].[TPSCompany] ([ID])
GO
ALTER
TABLE
[dbo].[CompanyProduct]
CHECK
CONSTRAINT
[FK_CompanyProduct_TPSCompany]
GO
and
CREATE
TABLE
[dbo].[TPSCompany](
[ID] [
int
] IDENTITY(1,1)
NOT
NULL
,
[CompanyName] [nvarchar](100)
NOT
NULL
,
[ContactNumber] [nvarchar](50)
NOT
NULL
,
[DepartmentID] [tinyint]
NOT
NULL
,
[CreatedDate] [datetime]
NOT
NULL
,
[CreatedByID] [
int
]
NOT
NULL
,
CONSTRAINT
[PK_TPSCompanies]
PRIMARY
KEY
CLUSTERED
(
[ID]
ASC
)
WITH
(PAD_INDEX =
OFF
, STATISTICS_NORECOMPUTE =
OFF
, IGNORE_DUP_KEY =
OFF
, ALLOW_ROW_LOCKS =
ON
, ALLOW_PAGE_LOCKS =
ON
)
ON
[
PRIMARY
]
)
ON
[
PRIMARY
]
GO
ALTER
TABLE
[dbo].[TPSCompany]
WITH
CHECK
ADD
CONSTRAINT
[FK_TPSCompanies_Department]
FOREIGN
KEY
([DepartmentID])
REFERENCES
[dbo].[Department] ([ID])
GO
ALTER
TABLE
[dbo].[TPSCompany]
CHECK
CONSTRAINT
[FK_TPSCompanies_Department]
GO
and using DB first approach , I have created classes of these tables.
for my use I have created a viewmodel with followings code
public
class
CompanyProductVM
{
public
int
ID {
get
;
set
; }
[Required]
[Display(Name =
"Stock Name"
)]
[DataType(DataType.Text)]
public
string
StockName {
get
;
set
; }
public
int
CompanyID {
get
;
set
; }
[Required]
[Display(Name =
"Created Date"
)]
[DataType(DataType.DateTime)]
public
System.DateTime CreatedDate {
get
;
set
; }
public
int
CreatedByID {
get
;
set
; }
[Required]
[Display(Name =
"Stock Detail"
)]
[DataType(DataType.Text)]
public
string
StockDetail {
get
;
set
; }
public
virtual
TPSCompany TPSCompany {
get
;
set
; }
}
and I have CompanyProduct.cs as follow.
public
partial
class
CompanyProduct
{
public
int
ID {
get
;
set
; }
public
string
StockName {
get
;
set
; }
public
int
CompanyID {
get
;
set
; }
public
System.DateTime CreatedDate {
get
;
set
; }
public
int
CreatedByID {
get
;
set
; }
public
string
StockDetail {
get
;
set
; }
public
virtual
TPSCompany TPSCompany {
get
;
set
; }
}
when I tried to generate Controller using scaffolding with EF.I am unable to get ddl for company as I want to select company agaisnt each company.this simpily create Controller.and if i want to change TPSCOMPANY to IEnum or collection then it send error that unable to get metadata for the application.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Converting string to decimal
how to collapse div on page load time ..