TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sahil Dombe
NA
2
442
display data based on dropdlist selection using entity model
Jul 24 2018 5:49 AM
After selecting employee from dropdownlist it doesnt show anything
EMPLOYEE MODEL
namespace
Mactest1.Models
{
using
System;
using
System.Collections.Generic;
using
System.Web.Mvc;
public
partial
class
Newemployee
{
public
Newemployee()
{
this
.Newemployeetrans =
new
HashSet<Newemployeetran>();
}
public
decimal
EmpId {
get
;
set
; }
public
string
EmpName {
get
;
set
; }
public
string
Designation {
get
;
set
; }
public
string
Address {
get
;
set
; }
public
string
City {
get
;
set
; }
public
string
TelephoneNumber {
get
;
set
; }
public
List<Newemployee> Emplist {
get
;
set
; }
public
IEnumerable<SelectListItem> emplist
{
get
{
return
new
SelectList(Emplist,
"EmpId"
,
"EmpName"
);
}
}
public
virtual
ICollection<Newemployeetran> Newemployeetrans {
get
;
set
; }
}
}
EMPLOYEE CONTROLLER
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
using
Mactest1.Models;
using
System.Data.Objects.SqlClient;
using
Mactest1.Controllers;
namespace
Mactest1.Controllers
{
public
class
EmployeeController : Controller
{
VBTEST2Entities db =
new
VBTEST2Entities();
public
ActionResult Employee()
{
Newemployee emps =
new
Newemployee();
Class1 c =
new
Class1();
emps.Emplist = c.GetEmpName();
return
View(emps);
}
[HttpPost]
public
ActionResult Employee1(Newemployee model)
{
Newemployee emps =
new
Newemployee();
var emp = emps.Emplist.Where(e => e.EmpId == model.EmpId).FirstOrDefault();
emps.EmpId = emp.EmpId;
emps.EmpName = emp.EmpName;
emps.Designation = emp.Designation;
return
View(emps);
}
}
}
CLASS FILE TO RETRIEVE DATA FROM MODEL
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
using
Mactest1.Models;
using
System.Data.Objects.SqlClient;
namespace
Mactest1.Controllers
{
public
class
Class1
{
public
List<Newemployee> GetEmpName()
{
VBTEST2Entities db =
new
VBTEST2Entities();
var y = from s
in
db.Newemployees
select s;
return
(y.ToList());
}
}
}
VIEW
@model Mactest1.Models.Newemployee
@using System.Linq
@{
Layout =
null
;
}
<!DOCTYPE html>
<html>
<head>
<link rel=
"stylesheet"
href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css"
integrity=
"sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B"
crossorigin=
"anonymous"
>
<meta name=
"viewport"
content=
"width=device-width"
/>
<title>Index</title>
</head>
<body>
<div>
<div
class
=
"container"
>
<div
class
=
"row"
>
<div
class
=
"col-sm-4"
>
@using (Html.BeginForm(
"Employee"
,
"Employee"
, FormMethod.Post,
new
{ id =
"demoForm"
, name =
"demoForm"
}))
{
@Html.Label(
"Employee Name"
)
@Html.DropDownListFor(m => m.EmpName, Model.emplist,
"-SELECT Employee-"
,
new
{ id =
"Ddl"
})
<fieldset>
<div
class
=
"display-label"
>
<strong> @Html.DisplayNameFor(model => model.EmpId) </strong>
</div>
<div
class
=
"display-field"
>
@Html.DisplayFor(model => model.EmpId)
</div>
<div
class
=
"display-label"
>
<strong> @Html.DisplayNameFor(model => model.EmpName) </strong>
</div>
<div
class
=
"display-field"
>
@Html.DisplayFor(model => model.EmpName)
</div>
<div
class
=
"display-label"
>
<strong> @Html.DisplayNameFor(model => model.Designation) </strong>
</div>
<div
class
=
"display-field"
>
@Html.DisplayFor(model => model.Designation)
</div>
</fieldset>
<script src=
"~/Scripts/jquery-1.10.2.min.js"
></script>
<script type=
"text/javascript"
>
$(document).ready(
function
(){
$(
'#Ddl'
).change(
function
(){
$(
'demoForm'
).submit();
});
});
</script>
Reply
Answers (
1
)
Array Class Methods
Update post on facebook with c#