【发布时间】:2012-03-16 19:40:53
【问题描述】:
这个问题会有点长,我很抱歉 :)
我搜索了几天的最佳解决方案,以在 asp mvc 和 JQuery 中制作图片库。
主要问题是当用户单击拇指时显示图像。
我想让整个浏览器视图变黑并在中心显示图像(宽度/高度 100%)。
我做了一些东西并且它有效。但是有一些我没有解决的问题。
我是怎么做到的:
我有 ImagesController 和 Index 视图,该视图包含图像缩略图。 ImageID 我存储在图像标签的名称属性中。当用户单击拇指图像时,我调用此 jquery 函数:
$('.imageThumb').live('click', function (e) {
e.preventDefault();
$.ajax({ type: "POST",
url: '@Url.Content("~/Images/Show")',
data: "imgId=" + $(this)[0].name,
success: function (d) {
$(document.body).append(d);
$(document.body).css("overflow", "hidden");
}
})
});
此 Show 视图是显示所选图像的全屏浏览器视图:
<div id="bigWrap" style="background: #000; position: fixed; top: 0; left: 0; width: 100%;
height: 100%;">
<div id="leftPage" style="width: 100%; height: 100%; background: #000; float: left;
text-align: center; position: relative;">
<img id="imgDis" src="@Url.Content("~/" + Model.Path)" alt="@Model.MediaId"
style=" max-width: 90%;
max-height: 90%; " />
<div style="position: absolute; top: 1%; right: 0px;">
<input id="closeImage" type="image" src="btnClose.png"
onclick="$('#bigWrap').remove(); $('body').css('overflow', 'auto');" />
</div>
<div style="position: absolute; top: 45%; right: 0px;">
@using (Html.BeginForm("Next", "Images", FormMethod.Post, new { id = "nextImage" }))
{
@Html.HiddenFor(a => a.MediaId);
@Html.HiddenFor(a => a.Path);
<input id="btnNext" type="image" src="btnNext.png" />
}
</div>
</div>
</div>
当用户点击next 按钮时,我调用:
$(function () {
$('#nextImage').submit(function () {
$.ajax({
url: this.action,
type: this.method,
data: "m_id=" + $('#imgDis').attr('alt'),
beforeSend: function (xhr) {
$('#bigWrap').empty();
},
success: function (result) {
$('#bigWrap').prepend(result);
}
});
return false;
});
});
Next ActionMethod 返回相同的Show 视图,只是带有新模型(图片):
[HttpPost]
public ActionResult Next(int m_id)
...
return View("Show", model);
现在,我使用这种方法遇到的问题是:
- 当用户点击缩略图时显示,但 URL 保持不变:http://localhost:xxxx/Images
- 单击下一步按钮时,URL 仍然相同。
- 这仅适用于我在图像/索引中。如果我 从其他视图打开图像
使用相同的功能(来自 jquery 调用 Show 操作)Url 更改为 http://localhost:xxxx/Images/Show?imgId=47,下一个按钮仍然没有任何变化,当我关闭显示的视图时,我在浏览器中看到了空白页面。
所以当用户从索引页面观看图像并且用户对 url 不感兴趣时,我在这里所做的显然有效。但我想改变这一点,但我被困在这里。因此,欢迎任何想法做什么,如何修复或改变一切。
谢谢
【问题讨论】:
-
为什么不使用 jQuery 插件来做到这一点?
标签: jquery asp.net-mvc asp.net-mvc-3 jquery-ui razor