Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
4
Reply
How to remove values in ids variable from EmployeeCourse tab
ahmed salah
Oct 29 2016 3:40 PM
300
Reply
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(
"<tr><td><input type = 'hidden' name='empcourses["
+ index +
"].CourseId' value='"
+ e.Id +
"'/></td><td>"
+ e.CourseName +
"</td><td><input type='button' value='remove' class='r'/></td></tr>"
)
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))
{
<div>
<table id=
"tb"
></table>
<input type=
"submit"
value=
"save"
/>
<input type=
"text"
name=
"ids"
id=
"ids"
/>
</div>
<table id=
"tb"
>
</table>
}
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
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
when we change dropdown selected value which javascript func
Create Random Password fro each user registration