Retrieve course id and course name selected in edit view(get) when edit data

Posted by Ahmedsa under ASP.NET MVC on 8/27/2016 | Points: 10 | Views : 92 | Status : [Member] | Replies : 0
to explain what i need found in this link

I need when edit employee data show to me courses that submit before

this is my secnario

in create view

courses drowpdown user select three courses




then when click submit button for will have 3 courses submitted

I need to retrieve courses that submitted before for employee martin

from database

in edit view(get)

I need to show :

course name course id Delphi 1

Flash 2

c++ 3

and CourseId will be hidden

what i write in edit view to show selected course

my code as below for view and controller

Edit.cs.html view
@model WebCourse.Models.Customemployee2
@using (Html.BeginForm())
Name:@Html.TextBoxFor(a => a.Name)
<br />

<table id="tb2"></table>
<br />
<input type="submit" />


in empcourse controller

namespace WebCourse.Controllers
public class empcourseController : Controller
mycourseEntities db = new mycourseEntities();

// GET: empcourse

public ActionResult Edit(int id)
Employee old = db.Employees.Find(id);
if (old != null)
var vm = new Customemployee2();
vm.Name = old.Name;

ViewBag.CourseId = new SelectList(db.Courses.ToList(), "Id", "CourseName");
return View(vm);

model view Customemployee2
namespace WebCourse.Models
public class Customemployee2
public string Name { get; set; }
public int CourseId { get; set; }
public List<EmployeeCourse> Courses { get; set; }



(No response found.)

Login to post response