0

我尝试使用可编辑用户创建 webgrid.. 当我单击 webgrid 行时,我可以使用用户名编辑用户但是,为什么当通过 JavaScript 从 webgrid 发送到我的控制器时用户名的值总是为空?这是我的网络网格

<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());
            }
        }

有人可以告诉我并帮助我吗?

4

1 回答 1

0

我认为你的问题是,使用Valinsted 的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>
于 2013-08-26T06:59:24.477 回答