2014-09-04 6 views
0

그래서 사용자가 로그인 할 수있는 partialview.부분보기에 다시 게시를 처리하는 방법을

을 만들었습니다하지만 난 일반보기 나는 형태를 제출할 때 내가 "자식 조치가 작업을 재 수행 할 수 없습니다 오류가 발생합니다. "

이것은 부분보기를 처리하는 컨트롤러의 내 [HttpPost] 컨트롤러 동작이 분명히 NoGo를 리다이렉트하기 때문입니다.

사용자가 로그인 할 때 오류가 표시되지 않습니다. 부분보기의 단추를 눌렀을 때 명확하게하기 위해 아무런 문제가 없습니다.

Partialview에 로그인을 퍼 팅하는 이유는 사용자가 응용 프로그램 여기

의 모든 페이지에서 할 수 기호를해야하기 때문입니다 코드입니다 :

Controller for partialview Credentials: 

public ActionResult Identify() { 
     if(Session["User"] != null) { 
      return PartialView("Identified", Session["User"]); 
     } else { 
      return PartialView(); 
     } 
    } 

    [HttpPost] 
    [ValidateAntiForgeryToken] 
    public ActionResult Identify(Login login) { 
     if(ModelState.IsValid) { 
      Authenticate(login.LoginName, login.LoginPasscode); 
     } 
     return Redirect(Request.UrlReferrer.AbsolutePath); 
    } 


@model ViewModels.Login 

@using(Html.BeginForm("Identify", "Credentials")) { 
    @Html.AntiForgeryToken() 
    @Html.ValidationSummary(true) 
     <div class="editor-label"> 
      @Html.LabelFor(model => model.LoginName) 
      @Html.EditorFor(model => model.LoginName) 
      @Html.ValidationMessageFor(model => model.LoginName) 

      @Html.LabelFor(model => model.LoginPasscode) 
      @Html.EditorFor(model => model.LoginPasscode) 
      @Html.ValidationMessageFor(model => model.LoginPasscode) 

      <input class="button" type="submit" value="Log Ind" /> 

    </div> 

}

I _Layout에서 다음 줄을 사용하여 부분보기를 추가했습니다.

@{Html.RenderAction("Identify", "Credentials");} 

HomeController :

[HttpGet] 
    public ActionResult Index() { 
     db.Role.ToList(); 
     return View(); 
    } 

    [HttpPost] 
    public ActionResult Index(string Foo) { 
     db.Role.ToList(); 
     ViewBag.InTheBox = Foo; 
     return View(); 
    } 

와 마지막 홈 인덱스보기 :

@if (ViewBag.InTheBox == null){ 
    ViewBag.InTheBox = "Nothing In Here"; 
} 

<h1>@ViewBag.InTheBox</h1>  

@using (Html.BeginForm("Index","Home")) { 
    @Html.AntiForgeryToken() 
    @Html.ValidationSummary(true) 
    <input type="text" name="Foo"/> 
    <input type="submit" value="Submit" /> 
} 

편집 :

그래서 내가 문제를 해결하고 정말 간단했다하는 방법을 알아 냈어. 내 오버로드 된 메서드 Identify에는 httpget 변형 만 있어야합니다. 메서드의 httppost 변형이이 경우 Authenticate로 바뀌고 양식이 해당 메서드에 게시됩니다. 이 문제가 해결되었습니다. 아래 코드를 수정하십시오.

Controller for partialview Credentials: 

public ActionResult Identify() { 
     if(Session["User"] != null) { 
      return PartialView("Identified", Session["User"]); 
     } else { 
      return PartialView(); 
     } 
    } 

    [HttpPost] 
    [ValidateAntiForgeryToken] 
    public ActionResult Authenticate(Login login) { 
     if(ModelState.IsValid) { 
      Authenticate(login.LoginName, login.LoginPasscode); 
     } 
     return Redirect(Request.UrlReferrer.AbsolutePath); 
    } 


@model ViewModels.Login 

@using(Html.BeginForm("Authenticate", "Credentials")) { 
    @Html.AntiForgeryToken() 
    @Html.ValidationSummary(true) 
     <div class="editor-label"> 
      @Html.LabelFor(model => model.LoginName) 
      @Html.EditorFor(model => model.LoginName) 
      @Html.ValidationMessageFor(model => model.LoginName) 

      @Html.LabelFor(model => model.LoginPasscode) 
      @Html.EditorFor(model => model.LoginPasscode) 
      @Html.ValidationMessageFor(model => model.LoginPasscode) 

      <input class="button" type="submit" value="Log Ind" /> 

    </div> 

}

+0

나는 면도칼하지만 장고 MVC 앱 지나치게 익숙하지 않다 시도 모든 페이지에서 상속합니다 masterpage의 내부에 존재 . –

+0

나는 그것을 나의 특별한 문제에 어떻게 번역 할 지 모르겠다. – user2726213

답변

0

나는 논리의 유형을 것

RedirectToAcion(myActionName). 
+0

똑같은 일을한다. 자식 작업은 리디렉션 작업을 수행 할 수 없습니다. – user2726213