从另一个视图调用jquery函数

从另一个视图调用jquery函数,jquery,asp.net-mvc-3,spring-mvc,Jquery,Asp.net Mvc 3,Spring Mvc,我在名为index.cshtml的视图中有一个jquery函数'ShowerrorDialog',我需要从另一个视图test.cshtml调用相同的函数 function ShowerrorDialog(msg) { $("#errorDialog").html(msg); $("#errorDialog").dialog({ modal: true, dialogClass:'errorDialogClass', button

我在名为index.cshtml的视图中有一个jquery函数'ShowerrorDialog',我需要从另一个视图test.cshtml调用相同的函数

function ShowerrorDialog(msg) {
        $("#errorDialog").html(msg);
        $("#errorDialog").dialog({ modal: true, 
        dialogClass:'errorDialogClass',
         buttons: {
                 "OK" : function() {
                                $( "#errorDialog" ).dialog("close");
                                }
                   }
                   });
    }
test.cshtml:

@model IEnumerable<Ad_hocReporting.Models.GridModel>
@{
    Layout = null;
}
@{

    if (@Model.First().message == "Session Out")
    {
        //need to call ShowerrorDialog here
    }
    else
    {
        var grid = new WebGrid(Model, ajaxUpdateContainerId: "popup_content", rowsPerPage: 7);
        grid.Pager(WebGridPagerModes.NextPrevious);
    <div id="popup_content">
        @grid.GetHtml(tableStyle: "webGrid", rowStyle: "webGridRow", headerStyle: "webGridHeader", footerStyle: "webgridFooter", alternatingRowStyle: "webGridAlternateRow", columns: grid.Columns(

                                                   grid.Column("QueryTitle", (format: @<label>@item.QueryTitle</label>), header: "Query Name", style: "color:gray"),
                                        grid.Column((format: @<a href="#" onclick="javascript:OnEdit(this.id,'@item.QueryTitle');" class="selectcss" id=@item.QueryId>Select</a>), header: "Select"),
                                       grid.Column((format: @<input type="image" src="../../Content/images/DeleteRed.png" alt="delete" class="deletecss" onclick="javascript:OnDelete(this.id);" id=@item.QueryId'delete' />), header: "Delete")))
    </div>
    }

}
@model IEnumerable),标题:“选择”),
grid.Column((格式:@),标题:“Delete”))
}
}

您可以在通用文件中插入函数,并使用标签
include
来使用它。

这应该在注释中。为什么您不能将该函数保存在通用js文件中,并在需要的任何地方引用该文件?