2012-02-10 2 views
0

AJAX를 사용하여 파일을로드하려고합니다. 작동하지 않습니다.ASP.NET MVC AJAX 파일로드 중

보기

@{ 
    ViewBag.Title = "Index"; 
    Layout = null; 
} 

<html> 
<head> 
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $("button").click(function() { 
      $("div").load('test1.txt'); 
     }); 
    }); 
</script> 
</head> 
<body> 

<div><h2>Let AJAX change this text</h2></div> 
<button>Change Content</button> 

</body> 
</html> 

있는 test1.txt의 경로는 다음과 같습니다 ~/조회/아약스 /있는 test1.txt 뷰에 대한 경로가 ~/조회/아약스이다

/Index.cshtml

아이디어가 있으십니까?

답변

0

파일을 ~/Content/test1.txt으로 이동하십시오. 콘텐츠 경로는 MVC 라우팅 규칙의 영향을받지 않습니다.

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("button").click(function() { 
      $("div").load('@Url.Content("~/Content/test1.txt")'); 
     }); 
    }); 
</script> 
+0

감사합니다. 그것은 작동! – Pingpong