我尝试使用可编辑用户创建webgrid .. 当我点击webgrid的行时,我可以使用用户名编辑用户 但是,为什么当用JavaScript从webgrid发送到我的控制器时,username的值总是为null? 这是我的网格
<div class="form-box">
<div>
<input style="width:180px;" type="button" title="AddUser" value="Add New Users" onclick="location.href='@Url.Action("NewUser", "User") '" />
</div>
<br />
@if (grid != null)
{
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
mode: WebGridPagerModes.All,
columns: grid.Columns(
grid.Column(header:"Login Name",format:(item) => item.UserName),
grid.Column(header: "Full Name", format: (item) => item.FullName),
grid.Column("Email"),
grid.Column("Active"),
grid.Column("Master")
)
)
}
</div>
@section scripts
{
<script type="text/javascript">
$(function(){
$('tbody tr').live('hover', function(){
$(this).toggleClass('clickable');
}).live('click', function(){
var UserName = $(this).find('td:first').text();
location.href = '/User/EditUser/' + UserName;
});
});
</script>
}
这是我的控制器
public ActionResult User()
{
List<User> GetUser = _UserService.ShowUser(_HotelID);
ListUserViewModel model = UserBuilder.Build(GetUser);
return View(model);
}
public ActionResult EditUser(string UserName)
{
List<User> UserViewModel = _UserService.userViewModel(UserName, _HotelID);
if (UserViewModel.Count == 0)
{
return Redirect("HttpNotFound");
}
else
{
ListUserViewModel model = UserBuilder.Build(UserViewModel);
return View(model.listUser.FirstOrDefault());
}
}
有人可以告诉我并帮助我吗?
答案 0 :(得分:0)
我认为您的问题是,使用Val
代替text
。
<script type="text/javascript">
$(function(){
$('tbody tr').live('hover', function(){
$(this).toggleClass('clickable');
}).live('click', function(){
var UserName = $(this).find('td:first').val();
location.href = '/User/EditUser/' + UserName;
});
});
</script>