首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JQuery JCrop镜像MVC 4 Razor失败

JQuery JCrop镜像MVC 4 Razor失败
EN

Stack Overflow用户
提问于 2012-11-21 10:51:30
回答 1查看 5.1K关注 0票数 0

我正在尝试为我的MVC应用程序实现图像裁剪功能。

我正在学习本教程:http://www.askamoeba.com/Opensource/Opensourcedetail/132/Crop-Resize-Upload-Images-in-C-MVC3-MVC4-using-Jquery-Razor

我正在使用这个库:http://deepliquid.com/content/Jcrop.html

我是一个使用MVC和Razor的JQuery新手。

由于某些原因,此JQuery甚至没有注册:

代码语言:javascript
复制
@{
    ViewBag.Title = "Avatar Editor Page";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model SimsTemplate.Models.ViewModels.AvatarEditorModel

<script type="text/javascript">

    $(function() {
     jQuery('#avatarImageEditor').Jcrop({
        onChange: showPreview,
        onSelect: showPreview,
        setSelect: [@Model.Top, @Model.Left, @Model.Right, @Model.Bottom],
        aspectRatio: 1
    });
 });

function showPreview(coords)  {
     if (parseInt(coords.w) > 0)  {
         $('#Top').val(coords.y);
         $('#Left').val(coords.x);
         $('#Bottom').val(coords.y2);
         $('#Right').val(coords.x2);

         var width = @Model.Width;
         var height = @Model.Height;
         var rx = 100 / coords.w;
         var ry = 100 / coords.h;

         jQuery('#preview').css({
             width: Math.round(rx * width) + 'px',
             height: Math.round(ry * height) + 'px',
             marginLeft: '-' + Math.round(rx * coords.x) + 'px',
             marginTop: '-' + Math.round(ry * coords.y) + 'px'
         });
     }
}

</script>

 <div id="cropContainer">

     <div id="cropPreview">
     Preview:
        <img src="@Model.Avatar.ImageUrl" id="preview" alt="" />
    </div>

 <div id="cropDisplay">
 Display:
     <img src="@Model.Avatar.ImageUrl" id="avatarImageEditor" alt="" />
</div>

<input id="Top" name="Top" type ="text"/>
<input id="Bottom" name="Top" type ="text"/>
<input id="Left" name="Top" type ="text"/>
<input id="Right" name="Top" type ="text"/>

</div>

<div id="mainform">

@using (Html.BeginForm("Edit", "Avatar", FormMethod.Post))
{
    @Html.DisplayFor(x => x.Avatar.ImageUrl)         
    @Html.HiddenFor(x => x.Left)
    @Html.HiddenFor(x => x.Right)
    @Html.HiddenFor(x => x.Top)
    @Html.HiddenFor(x => x.Bottom)
    @Html.HiddenFor(x => x.Avatar.ImageUrl)
    <input type='submit' name='action' value='Crop' />
}
</div>

我已经正确设置了视图模型和控制器。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-05 00:24:35

你必须

Close (div id="mainform")

添加:在编辑视图中

代码语言:javascript
复制
@{
    @Scripts.Render("~/bundles/jquery")
    <script src="@Url.Content("~/Scripts/JCrop/jquery.Jcrop.js")" type="text/javascript"></script>
    <link rel="stylesheet" href="@Url.Content("~/Content/JCrop/jquery.Jcrop.css")" type="text/css" />
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13485616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档