jQuery Dialog没有工作/@Html.ActionLink没有触发click事件

时间:2014-06-20 09:31:11

标签: asp.net-mvc-4

//View       

@model List<MvcWebGridApp.Models.UserMaster>

@{
    ViewBag.Title = "GetListOfUsers";
    Layout = "~/Views/Shared/_Layout.cshtml";
     <style type="text/css">
       .grid{    width:100%; }
       a.lnkEdit
{
    background: url(../images/edit-icon.png) no-repeat bottom left;
     display: block;
     width: 150px;
     height: 150px;
     text-indent: -9999px; /* hides the link text */
}
    </style>
    var grid = new WebGrid(source: Model, canPage: true, canSort: true, rowsPerPage: 5);
}

<script type="text/javascript">
    $(document).ready(function () {
        var url = "";


        $("#dialog-edit").dialog({
            title: 'Create User',
            autoOpen: false,
            resizable: false,
            width: 400,
            show: { effect: 'drop', direction: "up" },
            modal: true,
            draggable: true,
            open: function (event, ui) {
            //  //  $(".ui-dialog-titlebar-close").hide();
             $(this).load(url);
            }
        });

        $(".lnkEdit").click("click", function (e) {
           alert("hello");
            e.preventDefault();// use this or return false
           url = $(this).attr("href");            
            $("#dialog-edit").dialog("open");

            //return false;
        });
    });
    </script>
<h2>GetListOfUsers</h2>

<div id="content">
    @{
    @grid.GetHtml(
    tableStyle: "grid",
         fillEmptyRows: false,
         headerStyle: "gvHeading",
         alternatingRowStyle: "gvAlternateRow",
         rowStyle: "gvRow",
         footerStyle: "gvFooter",

         mode: WebGridPagerModes.All,
         firstText: "<< First",
         previousText: "< Prev",
         nextText: "Next >",
         lastText: "Last >>",

    columns: new[] {
    grid.Column(columnName:"FullName",header:"Fullname"),
    grid.Column(columnName:"UserName",header:"UserName"),
    grid.Column(columnName:"Password",header:"Password"),
    grid.Column(columnName:"IsActive ?",format:@<text><input  type="checkbox" checked="@item.IsActive" disabled="disabled"/></text>),
    grid.Column("ContactusId", header: "Action", canSort:false,
     format: @<text>

    @Html.ActionLink("Edit", "Edit","User", new { UserId = item.UserId }, new { @class = "lnkEdit" })     
    </text>


  )       
     }) 
    }
</div>

<div id="DivToAppendPartialVoew"></div>
<div id="dialog-edit" style="display: none">
</div>

@Html.ActionClick未触发点击事件....

在触发click事件后,我希望jQuery对话框在对话框中显示另一个视图。

基本上我正在尝试使用webgrid进行crud操作,我正在使用jQuery对话框进行插入更新和删除。

1 个答案:

答案 0 :(得分:2)

这篇文章有点陈旧,但你可能要改变这个:

$(".lnkEdit").click("click", function (e) {

到此:

$(document).on("click", ".lnkEdit", function(e) {

或者这个:

$('body').on("click", ".lnkEdit", function(e) {

或者这个:

$(".lnkEdit").on("click", function(e) {