部分视图不渲染MVC剃刀视图引擎

3
这是我第一次使用部分视图,我无法获得实际的部分视图。Ajax函数被调用,控制器也被命中,ajax调用中的警报显示部分视图已经存在。但是,尽管控制台或者alert中有错误信息,我的div仍然是空的。
我的应用程序是一个MVC4应用程序,但我相信我只是在某个地方犯了一个愚蠢的错误,这不是MVC的问题 :)
经过几个小时的谷歌搜索,如果有人能帮助我让这个工作起来,我将非常高兴,并且非常感谢所有关于代码/ajax的提示/评论!
public PartialViewResult Groups()
{
        var person = _userRepository.GetCurrentUser();
        var connections = (from c in person.Person1 select c).ToList();
        var groups = _context.Groups.Where(g => g.GroupId == 1);

        var all = new GroupViewModel()
                      {
                          Connections = connections,
                          GroupDetailses = (from g in groups
                                            select
                                                new GroupDetails
                                                    {
                                                        Name = g.Name,
                                                        StartDate = g.StartDate,
                                                        StartedById = g.StartedById,
                                                    })

                      };
        return PartialView("Groups",all);
}

我的部分视图

@model Mvc4m.Models.GroupViewModel

<h2>Groups</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<h3>Create new Group</h3>
<div class="ui-widget">
    <label for="group">Groupname: </label>
    <input id="group" />
    <button onclick="addGroup()">Add</button>
</div>

@foreach (var item in Model.GroupDetailses)
{
    @Html.LabelFor(model => item.Name)<text> : </text>
    @Html.DisplayFor(model => item.Name)
}
<script>
    function addGroup() {
        $.get(
                "/Profile/AddGroup",
                {
                    Name: $("#group").val()
                });
        location.reload();
    };
</script>

我的Profile/Index页面上的Ajax调用

@model Mvc4m.Models.ProfileView

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<div id="test" style="background-color:Aqua; width:200px; height:100px"></div>

<button onclick="load()"></button>

<script type="text/javascript">
function load() {
    $.ajax({
        type: "GET",
        url: '/Profile/Groups',
        dataType: 'html',
        success: function (response) {
            $('#test').html(response);
            alert(response);
        },
        error: function (xhr, status, error) {
            alert(status + " : " + error);
        }

    });
}

</script>

真的,我在这个网站上无法正确格式化:( 我本来想用四个空格来表示代码部分,为什么又变成这样了呢? - Iris Classon
控制台中出现了什么错误? - Shyju
1个回答

0
原来代码是可以运行的,重启Visual Studio就解决了问题!有时候我真的很讨厌VS...

你正在使用哪个版本的Visual Studio? - Ethan Brown
最近我的2010 Ultimate经常会“抛锚”几次:/ - Iris Classon
唉,这不好玩。我一直在使用Visual Studio 11的Beta版本,看起来非常稳定,你可以试试看。顺便问一下,你的网站perfectdiet.com怎么了?我只收到了一个“禁止访问”的错误提示。 - Ethan Brown
@EthanBrown 噢,重定向出问题了,与网络酒店有关:/ 几个月前将网站移动到irisclasson.com/blog。我一直想尝试VS11,我想现在是时候了。昨天不得不强制关闭VS 10次,因为它不让我编辑我的cs文件 :/ - Iris Classon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接