同时使用onclick和href,根据先执行onclick根据onclick返回结果决定是否继续执行href的特性,onclick判断,href执行。
以下载为例:
function download_check(url, aid) {
var f = false;
$.ajax({
async: false,
cache: false,
type: "GET",
url: "/E_ModelManage/ModelAnalyse/QueryModulInfo?Model_Vsesion=" + Version + '&Model_Name=' + ModelName,//去controller中进行判断
success: function (data) {
if (data == "") {
$("#lr-loadmodel").attr("href", "/E_ModelManage/ModelAnalyse/PageOfficeLoadExecl?Model_Vsesion=" + Version + '&Model_Name=' + ModelName + '&userID=' + userID);//对a标签href赋值
f = true;
} else {
$.modalMsg(data, "error"); //页面提示
f = false;
}
}
});
return f;
}
```csharp
public ActionResult QueryModulInfo(string Model_Vsesion, string Model_Name)
{
Model_Name = HttpUtility.UrlDecode(Model_Name);
if (!string.IsNullOrEmpty(Model_Vsesion) && !string.IsNullOrEmpty(Model_Name))
{
Model_Name = System.IO.Path.GetFileNameWithoutExtension(Model_Name);
IEnumerable<E_A_MODELBASEINFOEntity> modelList = modelEmbedIBLL.GetModelByVersion(Model_Vsesion, System.IO.Path.GetFileNameWithoutExtension(Model_Name));
DataTable DTModel = CommonClass.AsDataTable<E_A_MODELBASEINFOEntity>(modelList);
if (DTModel.Rows.Count <= 0)
{
return Content("未查询到模型文件信息!");
}
string filePath = DTModel.Rows[0]["MODELPATH"].ToString();
if (!System.IO.File.Exists(Server.MapPath(filePath)))
{
return Content("模型文件不存在!");
}
}
return Content("");
}
public ActionResult PageOfficeLoadExecl(string Model_Vsesion, string Model_Name, string userID)
{
PageOffice.PageOfficeCtrl pc = new PageOffice.PageOfficeCtrl();
//pc.AddCustomToolButton("保存", "Save()", 1);
//pc.AddCustomToolButton("另存", "Save()", 2);
//pc.SaveFilePage = "/ModelAnalyse/SaveDoc"; //设置保存时访问的路径
pc.ServerPage = "/pageoffice/server.aspx"; //pageoffice服务器页面
string filePath = "";
if (!string.IsNullOrEmpty(Model_Vsesion) && !string.IsNullOrEmpty(Model_Name))
{
Model_Name = System.IO.Path.GetFileNameWithoutExtension(Model_Name);
DataTable DTModel = modelEmbedIBLL.GetModelByVersion(Model_Vsesion);
if (DTModel.Rows.Count <= 0)
{
pc.WebCreateNew(userID, DocumentVersion.Excel2007); //参数一:用户;参数二:文件类型
}
filePath = DTModel.Rows[0]["MODELPATH"].ToString();
if (System.IO.File.Exists(Server.MapPath(filePath)))
{
//参数一:文档路径;参数二:文档打开模式;参数三:操作当前文档的用户名。一般来说,UserName 应该采用登录到您的Web应用程序的当前用户的名称
pc.WebOpen(Server.MapPath(filePath), PageOffice.OpenModeType.xlsNormalEdit, userID);
}
}
ViewBag.EditorHtml = pc.GetHtmlCode("PageOfficeCtrl1");
ViewBag.Message = "模型加载成功";
return PartialView();
}