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 : 235 | Status : [Member] | Replies : 0
to explain what i need found in this link

http://www.mediafire.com/view/awanv95f4ldgr45/add_course_updated.jpg

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

Delphi

Flash

c++

then when click submit button for employee.it 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
<body>
<div>
@using (Html.BeginForm())
{
<div>
Name:@Html.TextBoxFor(a => a.Name)
<br />
Courses:@Html.DropDownList("CourseId")

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

</div>
</body>


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; }

}
}





Responses

(No response found.)

Login to post response