AspNetZero - 用户索引视图缩略图问题
AspNetZero - User index view thumbnail image question
我复制了 AspNetZero 解决方案中用于 "profile picture" 功能的所有代码。我指的是允许用户上传自己的照片的功能。
我已经将现有的模式、JS 文件和控制器方法分别复制到我的员工控制器和员工文件夹中,因为我想要相同的功能。
上传图像并保存到二进制对象 table 一切正常。
当我尝试在我的员工索引视图数据table 列中显示上传照片的缩略图时出现问题。我从解决方案的用户索引视图中复制了此功能。
呈现我的员工索引视图时,缩略图没有出现。当我单击图像缩略图时,它会打开新选项卡并为我复制的控制器方法抛出 404 错误。
这是在 users 索引视图中显示缩略图的 JS 代码:
targets: 1,
data: "userName",
render: function (userName, type, row, meta) {
var $container = $("<span/>");
if (row.profilePictureId) {
var profilePictureUrl = "/Profile/GetProfilePicture?t=" + row.profilePictureId;
var $link = $("<a/>").attr("href", profilePictureUrl).attr("target", "_blank");
var $img = $("<img/>")
.addClass("img-circle")
.attr("src", profilePictureUrl);
$link.append($img);
$container.append($link);
}
$container.append(userName);
return $container[0].outerHTML;
}
这是我的 employee 索引视图中的相同代码:
targets: 4,
orderable: true,
autoWidth: true,
data: "fullName",
render: function(fullName, type, row, meta) {
var $container = $("<span/>");
if (row.employeePictureId) {
var profilePictureUrl = "/Employee/GetProfilePictureById?id=" + row.employeePictureId;
var $link = $("<a/>").attr("href", profilePictureUrl).attr("target", "_blank");
var $img = $("<img/>").addClass("img-circle").attr("src", profilePictureUrl);
$link.append($img);
$container.append($link);
}
$container.append(fullName);
return $container[0].outerHTML;
}
不起作用的代码行是 ProfilePictureUrl 行。
var profilePictureUrl = "/Employee/GetProfilePictureById?id=" + row.employeePictureId;
如果我用用户 index.js 的行替换上面的行并调用配置文件控制器方法,它就可以正常工作。但是当我尝试调用我的员工控制器方法时,它一直抛出 404 错误。
我的员工控制器在我的解决方案中与配置文件控制器处于同一级别。两个控制器都属于我的 MVC 应用程序中的同一区域。
我刚刚解决了我的问题。还有另一个配置文件控制器位于区域文件夹之外。所以usersindex.js中使用的URL不需要写全路径。
用户照片功能正在点击应用程序根级别 的 配置文件控制器,而不是区域内部的控制器。
在我的例子中,我必须像对待我所在区域的所有模态和脚本一样对待 URL。
这是有效的解决方案。
var empPhotoUrl = abp.appPath + 'AreaName/Employee/GetProfilePictureById?id=';
我复制了 AspNetZero 解决方案中用于 "profile picture" 功能的所有代码。我指的是允许用户上传自己的照片的功能。 我已经将现有的模式、JS 文件和控制器方法分别复制到我的员工控制器和员工文件夹中,因为我想要相同的功能。
上传图像并保存到二进制对象 table 一切正常。
当我尝试在我的员工索引视图数据table 列中显示上传照片的缩略图时出现问题。我从解决方案的用户索引视图中复制了此功能。
呈现我的员工索引视图时,缩略图没有出现。当我单击图像缩略图时,它会打开新选项卡并为我复制的控制器方法抛出 404 错误。
这是在 users 索引视图中显示缩略图的 JS 代码:
targets: 1,
data: "userName",
render: function (userName, type, row, meta) {
var $container = $("<span/>");
if (row.profilePictureId) {
var profilePictureUrl = "/Profile/GetProfilePicture?t=" + row.profilePictureId;
var $link = $("<a/>").attr("href", profilePictureUrl).attr("target", "_blank");
var $img = $("<img/>")
.addClass("img-circle")
.attr("src", profilePictureUrl);
$link.append($img);
$container.append($link);
}
$container.append(userName);
return $container[0].outerHTML;
}
这是我的 employee 索引视图中的相同代码:
targets: 4,
orderable: true,
autoWidth: true,
data: "fullName",
render: function(fullName, type, row, meta) {
var $container = $("<span/>");
if (row.employeePictureId) {
var profilePictureUrl = "/Employee/GetProfilePictureById?id=" + row.employeePictureId;
var $link = $("<a/>").attr("href", profilePictureUrl).attr("target", "_blank");
var $img = $("<img/>").addClass("img-circle").attr("src", profilePictureUrl);
$link.append($img);
$container.append($link);
}
$container.append(fullName);
return $container[0].outerHTML;
}
不起作用的代码行是 ProfilePictureUrl 行。
var profilePictureUrl = "/Employee/GetProfilePictureById?id=" + row.employeePictureId;
如果我用用户 index.js 的行替换上面的行并调用配置文件控制器方法,它就可以正常工作。但是当我尝试调用我的员工控制器方法时,它一直抛出 404 错误。 我的员工控制器在我的解决方案中与配置文件控制器处于同一级别。两个控制器都属于我的 MVC 应用程序中的同一区域。
我刚刚解决了我的问题。还有另一个配置文件控制器位于区域文件夹之外。所以usersindex.js中使用的URL不需要写全路径。 用户照片功能正在点击应用程序根级别 的 配置文件控制器,而不是区域内部的控制器。 在我的例子中,我必须像对待我所在区域的所有模态和脚本一样对待 URL。 这是有效的解决方案。
var empPhotoUrl = abp.appPath + 'AreaName/Employee/GetProfilePictureById?id=';