2012-03-29 2 views
3

부분 뷰를 처음 사용하기 때문에 실제 부분 뷰를 얻을 수 없습니다. ajax 함수가 호출되고 컨트롤러가 히트되며 ajax 호출의 경고는 partialview가 있음을 나타냅니다. 하지만 오류가 콘솔 (또는 경고)에 기록되면 내 div는 그대로 비어있게됩니다. 내 응용 프로그램은 MVC4 응용 프로그램이지만, 나는 어딘가에 MVC의 어리석은 실수를 한 것 같다. :)부분 뷰 MVC 면도기를 사용하지 않습니다.

어색한 시간에 몇 시간 만 지나면 누구나 나에게 도움이 될 것이라고 행복해 할 것이다. 이 작업, 모든 팁/코드/아약스에 대한 의견은 크게 감사드립니다! 프로필/색인에

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); 
} 

내 PartialView

@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> 

내 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> 
+0

심각하게, 나는이 사이트에서 포맷팅 리그 릿을 얻을 수 없다 : (나는 4 칸으로 코드 부분을 의도했는데, 어떻게 이런 식으로 다시 나타 났는가? –

+0

콘솔의 에러는 무엇인가? ? – Shyju

답변

0

비주얼 스튜디오를 다시 시작이 속임수를 썼는지, 코드가 작동 밝혀! 나는 때때로 VS를 싫어한다 ...

+0

Visual Studio의 어떤 버전을 사용하고 있습니까? –

+0

2010 Ultimate, 하루에 몇 번 나랑 헤어지는 중입니다 :/ –

+0

어쩌면 재미 있지 않습니다. 저는 Visual Studio의 베타 버전을 사용하고 있습니다. 11, 그리고 정말 안정적으로 보이므로 시험해보고 싶을 수도 있습니다. 그런데 웹 사이트 (perfectdiet.com)는 무엇인가요? "금지 된"오류가 발생합니다. –

관련 문제