mvc5 ajax没有刷新部分视图

时间:2016-08-25 22:07:34

标签: ajax asp.net-mvc-5

我有一个视图,其中包含部分视图中的文本框,按钮和虚拟书。按下按钮后,文本框中的文本将放在书的第一页上,然后应刷新书籍(部分视图)。

使用Ajax,我可以调用方法PlaceText(将文本放在书的第一页/图像上),但它不会刷新局部视图_Book。

我试过

$("#services").load("_Book");

$("#services").load("PlaceText");
在阅读这些解决方案以解决类似问题之后,还有更多的事情,但似乎没有任何工作。出现allert(“ok”),但partialView不刷新

                        <script type ="text/javascript">
                            $(document).ready(function(){
                                $("#myLink").click(function (e) {
                                    e.preventDefault();
                                    var textboxvalue = $('input[name=your-name]').val();
                                    $.ajax({
                                        data: { name: textboxvalue },
                                        type: 'POST',
                                        url: '@Url.Action("PlaceText", "Home")',
                                        success: function (result) {

                                                $("#services").html("_Book");
                                                alert("ok");
                                        }

                                    });
                                });
                            });

                        </script>
                        @Html.ActionLink("Mehet", "PlaceText", null, new { id = "myLink" })

这是我的控制器:

    [HttpPost]
    [OutputCache(Duration = 0)]
    public ActionResult PlaceText(string name)
    {

        PointF firstLocation = new PointF(700f, 80f);

        string imageFilePath = Server.MapPath(@"~/images/demo1/elolap3.jpg");
        string imageFilePath2 = Server.MapPath(@"~/images/demo1/elolap1.jpg");
        Bitmap bitmap = (Bitmap)Image.FromFile(imageFilePath);//load the image file

        using (Graphics graphics = Graphics.FromImage(bitmap))
        {
            using (Font arialFont = new Font("Bigfish", 40))
            {
                graphics.DrawString(name, arialFont, Brushes.Blue, firstLocation);
            }
        }

        bitmap.Save(imageFilePath2);//save the image file
        return PartialView("_Book", db.imageModel.ToList());
    }

这是我的观点(索引):

    <section id="services" class="services service-section">
        @Html.Partial("_Book");
    </section>

我的部分观点:

<div class="Heidelberg-Book with-Spreads" id="Heidelberg-example-1">

@foreach (var image in Model)
{
    <div class="Heidelberg-Spread">
        <img src="@Url.Content(image.FilePath)" />
    </div>
}

</div>

0 个答案:

没有答案