2013-05-05 2 views
2

내 요구 사항은 동일한 페이지에서 다른 페이지로 리디렉션되지 않은 결과를 표시하는 것입니다. 나는 Ajax.BeginForm()으로 이것을하고있다. 다른 페이지로 리디렉션됩니다. 어느 누구도 이것을 도울 수 있습니까?MVC4의 Ajax.BeginForm()

내 JS 파일 :

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script> 

내보기 코드 :

@using (Ajax.BeginForm("UserAccountInfo", "Account", new AjaxOptions {UpdateTargetId = "result" })) 
{ 
@Html.ValidationSummary(true) 

<div id="result"></div> 

<div class="t-12-user">First Name </div> 

<div> @Html.TextBoxFor(model => model.FirstName, new { @class = "user-input-bx", MaxLength = "50"})</div> 

<div class="t-12-user"> Email Address </div> 

<div> @Html.TextBoxFor(model => model.EmailId, new { @class = "user-input-bx", MaxLength = "50" })</div> 

<div><input type="submit" value="Save" /> </div> 

    } 

컨트롤러 :

[HttpPost] 
public ActionResult UserAccountInfo(RegisterModel Model) 
{ 
// code 
    return Content("Thank you for subscribe", "text/html"); 
} 

의 Web.config :

<add key="ClientValidationEnabled" value="true" /> 
<add key="UnobtrusiveJavaScriptEnabled" value="true" /> 

이 하나 도움, 성공 메시지가 같은 페이지에 표시해야 할 수 있습니다 ..

+0

jquery before (ver. 1.8.3, 또는 조심성있는 아약스와 jquery 1.9.2의 새로운 버전을 확인하십시오. – hVostt

+0

@hVostt : js 파일에 문제가 있습니까? 만약 내가 다른 페이지를 리디렉션 참조를주고 제거합니다. 보여주는 결과. – Ram

+0

in AjaxOptions InsertionMode = InsertionMode.Replace를 추가하십시오. jquery가 전에 추가 된 경우 작동해야합니다. – hVostt

답변

1

반환 등 JSON. 나는 그것이 당신을 위해 일할 것이라고 생각합니다. 당신은이 두 가지 방법으로 할 수

+0

나는 끝냈다. Js 플러그인은 로컬 페이지에 배치됩니다. 지금 일하고있어. – Ram

0

...

해결 방법 1 : 당신은 귀하의 콘텐츠와 함께/조회/계정 폴더 안에 부분 뷰를 생성하고 그것을 반환해야합니다.

컨트롤러 :

[HttpPost] 
public ActionResult UserAccountInfo(RegisterModel Model) 
{ 
// code 
return PartialView("_yourPartialView", model); 
} 

Solution2 : 그냥 같은 뷰를 반환하고이 같은 뷰에 문자열을 전송하는 ViewBag 변수를 사용 ...

컨트롤러 :

[HttpPost] 
public ActionResult UserAccountInfo(RegisterModel Model) 
{ 
// code 
ViewBag.VariableName = "Thank you for subscribe"; 
return View(); 
} 

보기 :

@ViewBag.VariableName