如何删除编辑后控制器中的ID中的课程存储 [英] How to remove courses store in ids in edit post controller
问题描述
在编辑HTTP帖子中我需要删除存储在ids变量中的课程
注意我需要删除选择不编辑的课程
http://www.mediafire.com/view/awe5t3xlh6ghbgx /remove_ids_courses.jpg [ ^ ]
在jquery中存储已移除课程的值在ids变量
假设我删除了photoshop并将其闪存将值存储在ids变量中的值为3,4或者b $ b b / b
点击删除它会保存在变量ID中删除的课程值
< br $> b $ b array
$( < span class =code-string>#tb)。on( click, 。r, function (){
$(此跨度>)母体()的父()隐藏()。;
$( this )。parent()。prev()。prev()。find( input)。addClass( remove< /跨度>);
var ids = [];
var i = 0 ;
$( 。删除)。each( function (){
ids [i] = $( this )。val();
i ++;
});
for ( var k = 0 ; k< ids.length; k ++){
alert(ids [k]);
}
});
i显示每位员工的表格EmployeeCourse编辑得到以下内容
var index = 0 ;
$就({
网址:<跨度类= 代码串> 跨度> <跨度类= 代码串 > / EmployeeData工作/ getcoursesbyempid跨度>,
数据:{x:$( #hid)。val()},
成功: 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 跨度>数据= db.EmployeeCourses.Where(A => a.EmployeeId == X)。加入(db.Courses,A =>一种.CourseId,b => b.Id,(a,b)=> new {Id = a.CourseId,CourseName = b.CourseName});
return Json(data,JsonRequestBehavior.AllowGet);
}
In edit HTTP post i need to remove courses stored in ids variable 这篇关于如何删除编辑后控制器中的ID中的课程存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我的模式使用如下
< pre lang =C#> public class Cusomemp2
{
public int ID { get ; set ; }
public string 名称{ get 跨度>; set ; }
public 列表< EmployeeCourse> empcourses { get ; set ; }
}
删除编辑HTTPPOST的课程我在这里写的内容
<预郎= C#> [HttpPost]
<跨度类= 代码关键字>公共跨度>的ActionResult编辑(Cusomemp2定制)
{
// 我写的是从表EmployeeCourse中删除保存在ids中的课程
return View();
}
我的尝试:
如何删除编辑后控制器中的ID中的课程存储( #tb)。on( click, 。r, function (){
( this )。parent()。parent()。hide();
( this )。parent()。prev()。prev()。find( input)。addClass( remove );
var ids = [];
var i = 0 ;
note i need remove courses selected not edit
http://www.mediafire.com/view/awe5t3xlh6ghbgx/remove_ids_courses.jpg[^]
in jquery i store values of removed courses in ids variable
suppose i removed photoshop and flash it will store value of 3,4 in ids variable
below code when click remove it save values of courses removed in variable ids as
array
$("#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++;
});
for (var k = 0; k < ids.length; k++) {
alert(ids[k]);
}
});
i show courses per employee from table EmployeeCourse in edit get as following
var index = 0;
$.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);
}
my mode using as following
public class Cusomemp2
{
public int Id { get; set; }
public string Name { get; set; }
public List<EmployeeCourse> empcourses { get; set; }
}
when remove courses in edit HTTPPOST what i write here
[HttpPost]
public ActionResult Edit(Cusomemp2 custom)
{
//what i write to remove courses saved in ids from table EmployeeCourse
return View();
}
What I have tried:
how to remove courses store in ids in edit post controller("#tb").on("click", ".r", function () {
(this).parent().parent().hide();
(this).parent().prev().prev().find("input").addClass("remove");
var ids = [];
var i = 0;