2015-02-07 4 views
1

asp.net ajax에서 부분 뷰 응답이 html을 대체하고 부분 뷰만 렌더링됩니다. 아래의 코드에서 ActionLink "Steps"를 클릭하면 부분보기가 반환되고 Details.cshtml이 바뀝니다.asp.net mvc ajax에서 부분 뷰 렌더링시 오류

이 부분보기는 "main-content-div"div 만 바꾸면됩니다.

도와주세요. 감사합니다

보기 : Details.cshtml

<div class="main-body"> 

<table> 
    <tr> 
     <td class="left-sidebar extended"> 

      @Ajax.ActionLink("Steps", "Steps", new { id = ViewBag.Id }, new AjaxOptions { AllowCache = false, UpdateTargetId = "main-content-div", InsertionMode=InsertionMode.Replace }) 
     </td> 
     <td class="main-wrapper"> 

      <div class="main-content" id="main-content-div"> 
       This is the default stuff which I'll be replacing... 
      </div> 
     </td> 
     <td class="right-sidebar"></td> 
    </tr> 

</table> 

작업 방법 :

[HttpGet] 
    public PartialViewResult Steps(string id) 
    { 
     //reading model from db 
     return PartialView("~/Views/Author/Exercise/_StepsPartial.cshtml", Model); 
    } 

부분보기 : 당신은 당신의 PROJ에 jquery.unobtrusive-ajax.min.js를 추가 할 필요가

@model IEnumerable<Model> 
<div> 
    <div> 
     <input type="text" /> 
    </div> 
</div> 
+0

올바른 스크립트가로드되지 않았거나 명령 순서가 맞지 않기 때문입니다. –

답변

2

이 일을하기위한 요법. Nuget 콘솔 패키지 관리자 콘솔과 유형

이동합니다

Install-Package Microsoft.jQuery.Unobtrusive.Ajax 

당신은 단지 관련 스크립트에 _Layout.cshtml의 상단에 참조를 추가하거나 볼 필요가 : 아마

<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>