我在做一张表的增删改查的时候,在编辑的时候,需要获取当前选择行对应的Id,然后并且把选择行的Id的对于的数据取出来,代码如下:
列表a标签绑定:
Js代码:
url: '/Users/GetUserByUserId/'+UserId,
<script type="text/javascript"> //编辑->执行
FunctionActionEdit = function (UserId) { var _json = jQuery.param({ "UserId": UserId });//这是参数
$.ajax({
url: '/Users/GetUserByUserId/'+UserId,
type: 'get',
async: false,
data: _json,
dataType: 'json',
cache: false,
success: function (result) {
alert(result) $('#EditUser_Modal').modal('show');//bootstrap弹出窗体
}
})
} </script>
控制器代码:
JsonRequestBehavior.AllowGet 转换json
/// <summary>
/// 根据UserId查询
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public ActionResult GetUserByUserId(int Id)
{
Users user = new Users();
user.UserId = Id;
object objUsers = UserManager.SelectUserList_ByUserId(user); return Json(objUsers, JsonRequestBehavior.AllowGet);
}