【问题标题】:javascript not working in mvccontrib gridjavascript 在 mvccontrib 网格中不起作用
【发布时间】:2011-08-14 08:51:35
【问题描述】:
<% Html.Grid(Model.InnerModel.ParamaterDetails)
            .Empty("No data available")
            .Columns(column =>
            {
                column.For(x => x.MinValue).Named("Possible Min Value");
                column.For(x => x.MaxValue).Named("Possible Max Value");
                column.For(x => x.ScoreValue).Named("Bespoke Score Value");
                column.For(x => "<input type='button' name='button' class='btn' id='editOpenDialog' value='Edit' onclick=javascript:editParametersDialog('" + x.ID + "'); />").DoNotEncode();
            }).Render(); %>


<%Html.EndForm(); %>
<script type="text/javascript">
    function editParametersDialog(ID) {
        // Go back to the server and get the data for the road card timetable
        $.ajax({
            url: "GetDetails",
            type: "POST",
            data: "ID=" + ID,
            dataType: "json",
            success: function(data) {
                UpdateEditDialog(data);
                $('#addEditDialog').dialog('open');
            },
            error: function(jqXHR, textStatus, errorThrow) { alert(jqXHR); alert(textStatus); }
        });
    }

    function UpdateEditDialog(data) {
        $("#MinValue").val(data.MinValue);
        $("#MaxValue").val(data.MaxValue);
        $("#ScoreValue").val(data.ScoreValue);
    }

    $(document).ready(function() {
    });

</script>

GetDetails above is in controller
 [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult GetDetails (int ID)
        {
// some code here
}

onclick 调用 javascript:editParametersDialog 不起作用。它不会被唤起。 任何线索我可能做错了什么。

我可以发现 javascript:editParametersDialog 不会变成蓝色,这通常是这种情况。

【问题讨论】:

  • 您的代码看起来不错。什么不会被调用? editParametersDialog javascript 方法还是 GetDetails 控制器操作?
  • 我在 Mozilla javascript 调试器中检查,代码被触发 bt 在打开对话框的行上失败,错误:“对象不支持此属性或方法”
  • 好的,这与您最初提出的问题完全不同。请使用相关详细信息更新您的问题。似乎您没有包含 jQuery UI,或者您没有为 addEditDialog DOM 元素设置对话框。

标签: javascript asp.net-mvc json mvccontrib-grid


【解决方案1】:
<div id="addEditDialog" ></div>

your code is ok but u didn't put 
<div id="addEditDialog"></div>
in the .aspx page. 

for show dialog box div tag is must. 
$('#addEditDialog').dialog('open');
using this code you say div tag is show as popup.
Do it and try this one again. 

【讨论】:

    猜你喜欢
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 2023-01-15
    • 2011-02-23
    • 2012-10-02
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多