Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ASP.NET MVC 4 JQuery对话框_Javascript_Jquery_Asp.net Mvc_Jquery Ui - Fatal编程技术网

Javascript ASP.NET MVC 4 JQuery对话框

Javascript ASP.NET MVC 4 JQuery对话框,javascript,jquery,asp.net-mvc,jquery-ui,Javascript,Jquery,Asp.net Mvc,Jquery Ui,我想修改ASP.NET MVC 4模板网站上的javascript,以便模板附带的用于登录/注册操作的对话框可以用于代码中具有“.ajax link”类的任何链接。所以我在AjaxLogin.js中做了一些更改,现在看起来像这样: //... $('.ajax-link').each(function () { $(this).click(function (e) { var link = $(this), url = link.attr('hr

我想修改ASP.NET MVC 4模板网站上的javascript,以便模板附带的用于登录/注册操作的对话框可以用于代码中具有“.ajax link”类的任何链接。所以我在AjaxLogin.js中做了一些更改,现在看起来像这样:

//...

$('.ajax-link').each(function () {
    $(this).click(function (e) {
        var link = $(this),
            url = link.attr('href');

        var separator = url.indexOf('?') >= 0 ? '&' : '?';

        $.get(url + separator + 'content=1')
        .done(function (content) {

            var dialog = $('<div class="modal-popup"">' + content + '</div>')
                .hide() // Hide the dialog for now so we prevent flicker
                .appendTo(document.body)
                .filter('div') // Filter for the div tag only, script tags could surface
                .dialog({ // Create the jQuery UI dialog
                    dialogClass: 'fi-dialog',
                    title: link.data('dialog-title'),
                    modal: true,
                    resizable: false,
                    draggable: true,
                    width: link.data('dialog-width') || 600,
                    beforeClose: function () { resetForm($(this).find('form')); }
                })
                .find('form') // Attach logic on forms
                    .submit(formSubmitHandler)
                .end();

            dialog.dialog('open');
        });

        // Prevent the normal behavior since we use a dialog
        e.preventDefault();
    });
});

//...
/。。。
$('.ajax链接')。每个(函数(){
$(此)。单击(函数(e){
var link=$(此),
url=link.attr('href');
var separator=url.indexOf(“?”)>=0?“&”:“?”;
$.get(url+分隔符+'content=1')
.完成(功能(内容){

var dialog=$('实际上,您只需要对
AjaxLogin.js
脚本进行2次非常细微的修改即可实现此功能

第一次修改是在文件末尾,在那里有一个选择器数组。您只需添加
.ajax链接
选择器:

// List of link ids to have an ajax dialog
var links = ['#loginLink', '#registerLink', '.ajax-link'];
第二个修改是在
resetForm
函数中进行的,以便在尝试重置窗体之前添加一个检查。因为如果正在渲染的部分中没有窗体,则在尝试关闭对话框时会出现错误:

var resetForm = function ($form) {
    // make sure that there's a form before attempting to reset its elements
    if ($form.length < 1) {
        // No form inside the partial => we have nothing more to do here
        return;
    }

    // We reset the form so we make sure unobtrusive errors get cleared out.
    $form[0].reset();

    getValidationSummaryErrors($form)
        .removeClass('validation-summary-errors')
        .addClass('validation-summary-valid')
};
采取相应的行动:

public ActionResult Foo()
{
    // return a PartialView or whatever you want to popup in the dialog
    return Content("hello world from a jQuery Dialog");
}

它将在对话框中显示Foo操作的结果,与登录和注册操作的方式完全相同。

实际上,您只需要对
AjaxLogin.js
脚本进行2次非常细微的修改即可完成此操作

$('.ajax-link').each(function () {
    $(this).click(function (e) {
        var link = $(this),
            url = link.attr('href');

        var separator = url.indexOf('?') >= 0 ? '&' : '?';

         //clear all cashed dialog form
        $("div.modal-popup").remove();
第一次修改是在文件末尾,在那里有一个选择器数组。您只需添加
.ajax链接
选择器:

// List of link ids to have an ajax dialog
var links = ['#loginLink', '#registerLink', '.ajax-link'];
第二个修改是在
resetForm
函数中进行的,以便在尝试重置窗体之前添加一个检查。因为如果正在渲染的部分中没有窗体,则在尝试关闭对话框时会出现错误:

var resetForm = function ($form) {
    // make sure that there's a form before attempting to reset its elements
    if ($form.length < 1) {
        // No form inside the partial => we have nothing more to do here
        return;
    }

    // We reset the form so we make sure unobtrusive errors get cleared out.
    $form[0].reset();

    getValidationSummaryErrors($form)
        .removeClass('validation-summary-errors')
        .addClass('validation-summary-valid')
};
采取相应的行动:

public ActionResult Foo()
{
    // return a PartialView or whatever you want to popup in the dialog
    return Content("hello world from a jQuery Dialog");
}
它将在对话框中显示Foo操作的结果,与登录和注册操作的方式完全相同

$('.ajax-link').each(function () {
    $(this).click(function (e) {
        var link = $(this),
            url = link.attr('href');

        var separator = url.indexOf('?') >= 0 ? '&' : '?';

         //clear all cashed dialog form
        $("div.modal-popup").remove();
。 .

。 . .


$(文档).ready(函数(){
var UIDialogId=0;
$('.UIDialogOpen').live('click',函数(e){
e、 预防默认值();
UIDialogId++;
$('', {
'id':$(this.attr('data-dialog-id')!==未定义?$(this.attr('data-dialog-id'):'UIDialog'+UIDialogId,
“类”:“UIDialog”
}).appendTo('body')。对话框({
标题:$(this.attr('data-dialog-title')!==未定义?$(this.attr('data-dialog-title'):'Message',
位置:[“中心”,“中心”],
模态:真,可调整大小:假,zIndex:10000,自动打开:真,
minWidth:$(this).attr('data-dialog-minWidth')!==未定义?$(this).attr('data-dialog-minWidth'):'300px',
minHeight:$(this).attr('data-dialog-minHeight')!==未定义?$(this).attr('data-dialog-minHeight'):'300px',
maxWidth:$(this).attr('data-dialog-maxWidth')!==未定义?$(this).attr('data-dialog-maxWidth'):'300px',
maxHeight:$(this).attr('data-dialog-maxHeight')!==未定义?$(this).attr('data-dialog-maxHeight'):'300px',
关闭:功能(事件、用户界面){
$(this.remove();
}
})
//.load(this.href);
//或//使用.load(this.href);并在附加行下方添加注释或删除。
.append('Hi..This is Testing');
$('.UIDialogClose,.UIDialogCancel').live('click',函数(e){
var obj=$(此)
e、 预防默认值();
对象父对象('.UIDialog').dialog('close');
});
});
});

@ActionLink(“ActionLinkName”、“MethodeName”、“ControllerName”,新的{Id=2 },新的{@class=“UIDialogOpen”,数据\u对话框\u title=“UI对话框消息”}) @ActionLink(“ActionLinkName”、“MethodeName”、“ControllerName”、null、new{ @class=“UIDialogOpen”,数据\u对话框\u title=“UI对话框消息”})

$(文档).ready(函数(){
var UIDialogId=0;
$('.UIDialogOpen').live('click',函数(e){
e、 预防默认值();
UIDialogId++;
$('', {
'id':$(this.attr('data-dialog-id')!==未定义?$(this.attr('data-dialog-id'):'UIDialog'+UIDialogId,
“类”:“UIDialog”
}).appendTo('body')。对话框({
标题:$(this.attr('data-dialog-title')!==未定义?$(this.attr('data-dialog-title'):'Message',
位置:[“中心”,“中心”],
模态:真,可调整大小:假,zIndex:10000,自动打开:真,
minWidth:$(this).attr('data-dialog-minWidth')!==未定义?$(this).attr('data-dialog-minWidth'):'300px',
minHeight:$(this).attr('data-dialog-minHeight')!==未定义?$(this).attr('data-dialog-minHeight'):'300px',
maxWidth:$(this).attr('data-dialog-maxWidth')!==未定义?$(this).attr('data-dialog-maxWidth'):'300px',
maxHeight:$(this).attr('data-dialog-maxHeight')!==未定义?$(this).attr('data-dialog-maxHeight'):'300px',
关闭:功能(事件、用户界面){
$(this.remove();
}
})
//.load(this.href);
//或//使用.load(this.href);并在附加行下方添加注释或删除。
.append('Hi..This is Testing');
$('.ui对话框关闭,.ui拨号