2013-12-19 4 views
0
Public class ItemController : Controller 
{ 
    public ActionResult Index() 
    { 
     return View("Index"); 
    } 

    public ActionResult ItemDescription() 
    { 
     return View("ItemIndex"); 
    } 
} 

지금이 항목 폴더리디렉션 asp.net MVC 컨트롤러 액션 메소드에서 발생하지

뷰 1에서 두 개의 뷰는

itemIndex라는

@{ 
    ViewBag.Title = "ItemIndex"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 
<h2>ItemIndex</h2> 
<input type="button" value="Next" onclick="redirecttodetails()" /> 
<script type="text/javascript"> 
    function redirecttodetails() 
    { 
     $.ajax({ 
       url: '@Url.Action("Index", "Item")', 
       type: 'POST' 
     }); 
    } 
</script> 
을 itemIndex라는

이제는 ItemIndex보기에 빨간색으로 표시 할보기를 클릭하여 단추가 있습니다. 색인보기로 어떤 일도 일어나지 않습니다.

제안 사항?

답변

2

그냥 window.location.href을 사용하십시오. $.ajax은 리디렉션하지 않습니다.

function redirecttodetails() 
{ 
    window.location.href = '@Url.Action("Index", "Item")'; 
} 
+0

@ user2465036, 기꺼이 도와 드리겠습니다. – Satpal

1

아약스는 사용자를 새 페이지로 리디렉션하지 않습니다. 이것을 다음으로 변경하십시오 :

function redirecttodetails() 
{ 
    window.location.href = '@Url.Action("Index", "Item")'; 
} 
+0

해결책 감사합니다. 두 대답을 모두 고칠 수는 없네. 다른 사람이 너보다 1 분 먼저 대답 한 것 같아. 어쨌든 고마워. – user2465036