如何从视图到控制器获取值

时间:2015-02-02 07:25:16

标签: jquery asp.net-mvc

我在这个表中有一个动态表有多个列,比如名称age marksmark1 marks2 marks3和一个按钮删除时点击删除按钮行将删除数据库

我写了按钮点击jquery像这样

$(document).delegate(".delete"+this.name, "click", function () {
     $.ajax({
        url: '@Url.Action("Deletesutdentrecord","StudentDetails")',
        success: function () {
            var valid = true
    if (confirm('are you sure to delete this?.'))
        $(this).closest('tr').remove();
    valid = false;
}
    });
});      

我的控制器代码是

 public JsonResult Deletesutdentrecord()
    {
        try
        {
            StudentViewModel studentViewModel = new StudentViewModel();
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@Name", studentViewModel.Name);
            result = DataHelper.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Deletestudent", parameters);               
            return Json(result);
        }
        catch (Exception)
        {
            throw new ApplicationException("Error");
        }
    } 

我的观点是

  $.each(data.list, function (index, item) {
            var row = $('<tr class="data"></tr>');
            row.append($('<td class="name"></td>').text(item.Name));
            row.append($('<td class="age"></td>').text(item.Age));
            row.append($('<td ><input type="text" value=' + item.Marks1 + ' size="10px" class="marks" id=marks1_' + index + ' name=' + index + ' maxlength="3"/></td>'));
            row.append($('<td ><input type="text" value=' + item.Marks2 + ' size="10px" class="marks" id=marks2_' + index + ' name=' + index + ' maxlength="3"/></td>'));
            row.append($('<td ><input type="text" value=' + item.Marks3 + ' size="10px" class="marks" id=marks3_' + index + ' name=' + index + ' maxlength="3"/></td>'));               
            row.append($('<td><input type="Button" value="Edit" class=edit_'+index+'</td>'));
            row.append($('<td id=delete_'+index+'><input type="Button" value="Delete" class="delete" </td>'));
     });

但是在我的控制器中它显示空值如何获取删除行值的值

0 个答案:

没有答案