Problem in server side
I need to remove values found in string ids variable under Edit HTTP Post
from EmployeeCourse table
- public ActionResult Edit(FormCollection form)
- {
- string ids = form["ids"];
- // Remove values found in ids variable from EmployeeCourse table in database
- return View();
- }
The processes of my application is
1- get courses for every employee from EmployeeCourse table column CourseId in Edit get
- $.ajax({
- url: "/Employeedata/getcoursesbyempid",
- data:{x:$("#hid").val()},
- success: function (res) {
- $.each(res, function (i, e) {
- $("#tb").append("
")+ index + "].CourseId' value='" + e.Id + "'/> " + e.CourseName + " - index++;
- });
- }
- })
- });
- public JsonResult getcoursesbyempid(int x)
- {
- db.Configuration.ProxyCreationEnabled = false;
- var data = db.EmployeeCourses.Where(a => a.EmployeeId == x).Join(db.Courses, a => a.CourseId, b => b.Id, (a, b) => new { Id = a.CourseId, CourseName = b.CourseName });
- return Json(data, JsonRequestBehavior.AllowGet);
- }
2-If i remove courses then it will store in text box ids as 1,2.
The value stored in string ids variable get it from text box name ids found in view Edit get This text box store removed courses as 1,2 and after this click save button to remove from EmployeeCourse table in database.
To get values removed in text box name ids i do as following
- $("#tb").on("click", ".r", function () {
- $(this).parent().parent().hide();
- $(this).parent().prev().prev().find("input").addClass("remove");
- var ids = [];
- var i = 0;
- $(".remove").each(function () {
- ids[i] = $(this).val();
- i++;
- });
- $("#ids").val(ids);
- });
- @using (Html.BeginForm("Edit", "Employeedata", FormMethod.Post))
- {
"tb">
- "submit" value="save" />
- "text" name="ids" id="ids" />
"tb">
- }
3-after this i will click save to remove course 1 and 2 as example from EmployeeCourse table
Process No 3 this is actually what i need
- public ActionResult Edit(FormCollection form)
- {
- string ids = form["ids"];
- // Remove values found in ids variable from EmployeeCourse table in database
- return View();
- }
The image below have details of EmployeeCourse Table

Manas MohapatraPosted Oct 31, 2016, 1:35 AM
ahmed salahPosted Oct 30, 2016, 4:59 PM
in my case i using comma separated in server side
string ids = form["ids"];
var result = db.EmployeeCourses.Where(t => ids.Contains(t.CourseId);
db.EmployeeCourses.RemoveRange(result);
db.SaveChanges();
i have two questions
1- what i write after contain function t.CourseId or t.Id
2-Value after contain t.Id or t.CourseId is integer but ids variable is string how to do casting or parsing
3- how to separate values of courses in 1,2 how to take values between comma
ahmed salahPosted Oct 30, 2016, 4:38 PM
Manas MohapatraPosted Oct 30, 2016, 7:00 AM