0 Replies - 568 Views - Last Post: 18 August 2016 - 04:21 PM

#1 ahmedba   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 150
  • Joined: 24-January 14

Cannot add record in ProjectEmployee Table when Employee drop down cha

Posted 18 August 2016 - 04:21 PM

I have 3 table join with relation and it have models

Project Table
Id primary key increment identity

Employee table
Id primary key increment identity

ProjectEmployee Table
Id primary key increment identity
ProjectId forign key project table
EmployeeId forign key Employee table

in view i have two drop down list
first for Project
second for Employee
I need when i select value from drop down project
then select value from employee added in database then
show on table one view in same page view
sample what i need is
Project drop down user select (project1)
Employee drop down user select name (ahmed)
on change event of employee drop down add record in database and show what added in tr td
project name employee
project1 ahmed
I can fill drop down project and drop down Employee
with data
i cannot add data in database sql server when select from employee add record in database and show
what added in table as tr and td
my ProjectEmployee controller as following

namespace LinqProject.Controllers
    public class ProjectEmployeeController : Controller
        mytaskdbEntities db = new mytaskdbEntities();
        // GET: ProjectEmployee
        public ActionResult Index()
            return View(db.ProjectEmployees.ToList());
        public ActionResult Create()
            ViewBag.EmployeeId = new SelectList(db.Employees.ToList(),"Id", "fname");
            ViewBag.ProjectId = new SelectList(db.Projects.ToList(),"Id", "Projectname");
            return View();
        public ActionResult Create(ProjectEmployee PE)
            return view();

my ProjectEmployee view is (show what added in sql server in table tr td)

@model LinqProject.Models.ProjectEmployee
    Layout = null;

<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
    <script src="~/Scripts/jquery-1.10.2.js"></script>
        $(function () {
            $("#EmployeeId").change(function () {
                    type: "POST", //HTTP POST Method  
                    url: "ProjectEmployee/Create", // Controller/View   
                    data: { //Passing data  
                        Project: $("#ProjectId").val(),   
                        Employee: $("#EmployeeId").val(),


        @using (Html.BeginForm())
            <input type="submit" value="save" />

I writing code above and i try to add record in ProjectEmployee table and show what i added in tr td
but how to add record in table projectemployee table
i cannot do it by code
can you modify the code to add record in database and show the record added in same view

Is This A Good Question/Topic? 0
  • +

Page 1 of 1