title: How to handle postback in partial view
body: <p>So i have made a partialview where users can sign in.</p>
  
  <p>But when i submit forms i regular views i get an error 
  "Child actions are not allowed to perform redirect actions."</p>
  
  <p>This i because my [HttpPost] controller action in the controller that handles the partial view redirects and thats a NoGo apparently.</p>
  
  <p>I dont get the error when a user logs in. To clarify when the button in the partial view is pressed there is no problem.</p>
  
  <p>The reason for puting the login in a Partialview is because a user should be able sign in from any page in the application</p>
  
  <p>Here Is the code:</p>
  
  <pre><code>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)
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.LoginName)
              @Html.EditorFor(model =&gt; model.LoginName)
              @Html.ValidationMessageFor(model =&gt; model.LoginName)
  
              @Html.LabelFor(model =&gt; model.LoginPasscode)
              @Html.EditorFor(model =&gt; model.LoginPasscode)
              @Html.ValidationMessageFor(model =&gt; model.LoginPasscode)
  
              &lt;input class="button" type="submit" value="Log Ind" /&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>}</p>
  
  <p>I have added the partial view by using the following line in _Layout</p>
  
  <pre><code>    @{Html.RenderAction("Identify", "Credentials");}
  </code></pre>
  
  <p>HomeController:</p>
  
  <pre><code>  [HttpGet]
      public ActionResult Index() {
          db.Role.ToList();
          return View();
      }
  
      [HttpPost]
      public ActionResult Index(string Foo) {
          db.Role.ToList();
          ViewBag.InTheBox = Foo;
          return View();
      }
  </code></pre>
  
  <p>and last home index view:</p>
  
  <pre><code>@if (ViewBag.InTheBox == null){
      ViewBag.InTheBox = "Nothing In Here";
  }
  
  &lt;h1&gt;@ViewBag.InTheBox&lt;/h1&gt;    
  
  @using (Html.BeginForm("Index","Home")) {
      @Html.AntiForgeryToken()
      @Html.ValidationSummary(true)
      &lt;input type="text" name="Foo"/&gt;
      &lt;input type="submit" value="Submit" /&gt;
  }
  </code></pre>
  
  <p><strong>edit:</strong></p>
  
  <p>So i figured out how to solve the problem and it was really simple. My overloaded method Identify should only have a httpget variant. The httppost variant of the method was renamed in this case to Authenticate and the form posts to that method. This resolved the problem. Correct code below.</p>
  
  <pre><code>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)
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.LoginName)
              @Html.EditorFor(model =&gt; model.LoginName)
              @Html.ValidationMessageFor(model =&gt; model.LoginName)
  
              @Html.LabelFor(model =&gt; model.LoginPasscode)
              @Html.EditorFor(model =&gt; model.LoginPasscode)
              @Html.ValidationMessageFor(model =&gt; model.LoginPasscode)
  
              &lt;input class="button" type="submit" value="Log Ind" /&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>}</p>