How to get label text from table reference on database based on TableName and FieldName
Problem
How to get label text from table reference on database based on TableName and FieldName dynamically from database and show on view createEmployee .
Details
Meaning i need to get label text dynamically from database not static from model
SO that Every Time i need to change text of label i will change it from database depend on reference table
AND No need to change from code .
IF You give me function or any thing general because i have more models and view i need to make like that)
Tools used sql server 2012 and visual studio 2017 asp.net core 2.1
Database Have two tables Employee and Reference
Reference Table (have 3 key as composit keys(Code,TableName,FieldName))
Models classes Include HRContext
public class ReferenceFile
{
public int Code { get; set; }
public string TableName { get; set; }
public string FieldName { get; set; }
public string EnglishtextforLabel{ get; set; }
}
public class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public int EmployeeAge { get; set; }
}
public class HRContext : DbContext
{
public HRContext(DbContextOptions<HRContext> options)
: base(options)
{ }
public DbSet<Employee> Employees { get; set; }
public DbSet<ReferenceFile> ReferenceFiles { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Employee>()
.HasKey(t => new { t.EmployeeId });
modelBuilder.Entity<ReferenceFile>()
.HasKey(t => new { t.Code,t.TableName,t.FieldName });
}
}
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="EmployeeName" class="control-label"></label>
<input asp-for="EmployeeName" class="form-control" />
<span asp-validation-for="EmployeeName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="EmployeeAge" class="control-label"></label>
<input asp-for="EmployeeAge" class="form-control" />
<span asp-validation-for="EmployeeAge" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
</div>
Query Get Data from reference Table
SELECT TableName, FieldName,EnglishtextforLabel FROM ReferenceFile WHERE (FieldName = 'EmployeeId' ) AND TableName = 'Employee'
Here i need to get label on view create from table reference not static field name
Sample data for ReferenceTable
Code TableName FieldName EnglishtextforLabel
1 Employee EmployeeId Code
2 Employee EmployeeName Name
3 Employee EmployeeAge Age
As reference table above sample labels on view create must be Give me the Result below
:
Code
Name
Age
c# asp.net asp.net-mvc entity-framework-core
add a comment |
Problem
How to get label text from table reference on database based on TableName and FieldName dynamically from database and show on view createEmployee .
Details
Meaning i need to get label text dynamically from database not static from model
SO that Every Time i need to change text of label i will change it from database depend on reference table
AND No need to change from code .
IF You give me function or any thing general because i have more models and view i need to make like that)
Tools used sql server 2012 and visual studio 2017 asp.net core 2.1
Database Have two tables Employee and Reference
Reference Table (have 3 key as composit keys(Code,TableName,FieldName))
Models classes Include HRContext
public class ReferenceFile
{
public int Code { get; set; }
public string TableName { get; set; }
public string FieldName { get; set; }
public string EnglishtextforLabel{ get; set; }
}
public class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public int EmployeeAge { get; set; }
}
public class HRContext : DbContext
{
public HRContext(DbContextOptions<HRContext> options)
: base(options)
{ }
public DbSet<Employee> Employees { get; set; }
public DbSet<ReferenceFile> ReferenceFiles { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Employee>()
.HasKey(t => new { t.EmployeeId });
modelBuilder.Entity<ReferenceFile>()
.HasKey(t => new { t.Code,t.TableName,t.FieldName });
}
}
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="EmployeeName" class="control-label"></label>
<input asp-for="EmployeeName" class="form-control" />
<span asp-validation-for="EmployeeName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="EmployeeAge" class="control-label"></label>
<input asp-for="EmployeeAge" class="form-control" />
<span asp-validation-for="EmployeeAge" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
</div>
Query Get Data from reference Table
SELECT TableName, FieldName,EnglishtextforLabel FROM ReferenceFile WHERE (FieldName = 'EmployeeId' ) AND TableName = 'Employee'
Here i need to get label on view create from table reference not static field name
Sample data for ReferenceTable
Code TableName FieldName EnglishtextforLabel
1 Employee EmployeeId Code
2 Employee EmployeeName Name
3 Employee EmployeeAge Age
As reference table above sample labels on view create must be Give me the Result below
:
Code
Name
Age
c# asp.net asp.net-mvc entity-framework-core
add a comment |
Problem
How to get label text from table reference on database based on TableName and FieldName dynamically from database and show on view createEmployee .
Details
Meaning i need to get label text dynamically from database not static from model
SO that Every Time i need to change text of label i will change it from database depend on reference table
AND No need to change from code .
IF You give me function or any thing general because i have more models and view i need to make like that)
Tools used sql server 2012 and visual studio 2017 asp.net core 2.1
Database Have two tables Employee and Reference
Reference Table (have 3 key as composit keys(Code,TableName,FieldName))
Models classes Include HRContext
public class ReferenceFile
{
public int Code { get; set; }
public string TableName { get; set; }
public string FieldName { get; set; }
public string EnglishtextforLabel{ get; set; }
}
public class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public int EmployeeAge { get; set; }
}
public class HRContext : DbContext
{
public HRContext(DbContextOptions<HRContext> options)
: base(options)
{ }
public DbSet<Employee> Employees { get; set; }
public DbSet<ReferenceFile> ReferenceFiles { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Employee>()
.HasKey(t => new { t.EmployeeId });
modelBuilder.Entity<ReferenceFile>()
.HasKey(t => new { t.Code,t.TableName,t.FieldName });
}
}
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="EmployeeName" class="control-label"></label>
<input asp-for="EmployeeName" class="form-control" />
<span asp-validation-for="EmployeeName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="EmployeeAge" class="control-label"></label>
<input asp-for="EmployeeAge" class="form-control" />
<span asp-validation-for="EmployeeAge" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
</div>
Query Get Data from reference Table
SELECT TableName, FieldName,EnglishtextforLabel FROM ReferenceFile WHERE (FieldName = 'EmployeeId' ) AND TableName = 'Employee'
Here i need to get label on view create from table reference not static field name
Sample data for ReferenceTable
Code TableName FieldName EnglishtextforLabel
1 Employee EmployeeId Code
2 Employee EmployeeName Name
3 Employee EmployeeAge Age
As reference table above sample labels on view create must be Give me the Result below
:
Code
Name
Age
c# asp.net asp.net-mvc entity-framework-core
Problem
How to get label text from table reference on database based on TableName and FieldName dynamically from database and show on view createEmployee .
Details
Meaning i need to get label text dynamically from database not static from model
SO that Every Time i need to change text of label i will change it from database depend on reference table
AND No need to change from code .
IF You give me function or any thing general because i have more models and view i need to make like that)
Tools used sql server 2012 and visual studio 2017 asp.net core 2.1
Database Have two tables Employee and Reference
Reference Table (have 3 key as composit keys(Code,TableName,FieldName))
Models classes Include HRContext
public class ReferenceFile
{
public int Code { get; set; }
public string TableName { get; set; }
public string FieldName { get; set; }
public string EnglishtextforLabel{ get; set; }
}
public class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public int EmployeeAge { get; set; }
}
public class HRContext : DbContext
{
public HRContext(DbContextOptions<HRContext> options)
: base(options)
{ }
public DbSet<Employee> Employees { get; set; }
public DbSet<ReferenceFile> ReferenceFiles { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Employee>()
.HasKey(t => new { t.EmployeeId });
modelBuilder.Entity<ReferenceFile>()
.HasKey(t => new { t.Code,t.TableName,t.FieldName });
}
}
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="EmployeeName" class="control-label"></label>
<input asp-for="EmployeeName" class="form-control" />
<span asp-validation-for="EmployeeName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="EmployeeAge" class="control-label"></label>
<input asp-for="EmployeeAge" class="form-control" />
<span asp-validation-for="EmployeeAge" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
</div>
Query Get Data from reference Table
SELECT TableName, FieldName,EnglishtextforLabel FROM ReferenceFile WHERE (FieldName = 'EmployeeId' ) AND TableName = 'Employee'
Here i need to get label on view create from table reference not static field name
Sample data for ReferenceTable
Code TableName FieldName EnglishtextforLabel
1 Employee EmployeeId Code
2 Employee EmployeeName Name
3 Employee EmployeeAge Age
As reference table above sample labels on view create must be Give me the Result below
:
Code
Name
Age
c# asp.net asp.net-mvc entity-framework-core
c# asp.net asp.net-mvc entity-framework-core
asked 19 hours ago
ahmed abedelaziz
21
21
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Just use Model Binding... then you can use your FieldName in the label:
@model MyModelType
<label class="control-label">@Model.FieldName</label>
<input asp-for="EmployeeName" class="form-control" />
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53943006%2fhow-to-get-label-text-from-table-reference-on-database-based-on-tablename-and-fi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just use Model Binding... then you can use your FieldName in the label:
@model MyModelType
<label class="control-label">@Model.FieldName</label>
<input asp-for="EmployeeName" class="form-control" />
add a comment |
Just use Model Binding... then you can use your FieldName in the label:
@model MyModelType
<label class="control-label">@Model.FieldName</label>
<input asp-for="EmployeeName" class="form-control" />
add a comment |
Just use Model Binding... then you can use your FieldName in the label:
@model MyModelType
<label class="control-label">@Model.FieldName</label>
<input asp-for="EmployeeName" class="form-control" />
Just use Model Binding... then you can use your FieldName in the label:
@model MyModelType
<label class="control-label">@Model.FieldName</label>
<input asp-for="EmployeeName" class="form-control" />
answered 19 hours ago
Hooman Bahreini
3,1923730
3,1923730
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53943006%2fhow-to-get-label-text-from-table-reference-on-database-based-on-tablename-and-fi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown