title: asp.net core 2.0 not able to post a simple form
body: <p>I am trying to learn <strong>Asp.net Core 2.0</strong> and following a tutorial, I created a very simple form with only 1 property, the name of the <strong>Customer</strong>. I debugged with breakpoints I am not even able to hit the <strong>PostAsync</strong> method in <strong>CreateModel</strong></p>
  
  <p><strong>CreateModel</strong></p>
  
  <pre><code>public class CreateModel : PageModel
  {
      private readonly ApplicationDbContext _db;
      [BindProperty]
      public Customer Customer { get; set; }
      public CreateModel(ApplicationDbContext db)
      {
          _db = db;
      }
  
      public async Task&lt;IActionResult&gt; OnPostAsync()
      {
          if (!ModelState.IsValid) return Page();
  
          _db.Customers.Add(Customer);
          await _db.SaveChangesAsync();
          return RedirectToPage("/");
      }
  }
  </code></pre>
  
  <p><strong>Create.cs.html</strong></p>
  
  <pre><code>@page
  @model WebApplication1.Pages.CreateModel
  @{
      ViewData["Title"] = "Create";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  &lt;p&gt;Enter your name: &lt;/p&gt;
  
  &lt;form method="post"&gt;
      &lt;div asp-validation-summary="All"/&gt;
      &lt;div&gt;Name : &lt;input asp-for="Customer.Name"/&gt;&lt;/div&gt;
      &lt;input type="submit"/&gt;
  &lt;/form&gt;
  
  @section Scripts{ 
      @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
  }
  </code></pre>
  
  <p><strong>Customer</strong></p>
  
  <pre><code>public class Customer
  {
      public int Id { get; set; }
      [Required, StringLength(10)]
      public string Name { get; set; }
  
  }
  </code></pre>
  
  <p><strong>ApplicationDbContext</strong></p>
  
  <pre><code>public class ApplicationDbContext : DbContext
  {
      public ApplicationDbContext(DbContextOptions options) : base (options)    { }
  
      public DbSet&lt;Customer&gt; Customers { get; set; }
  }
  </code></pre>
  
  <p><strong>ConfigureServices method in my Startup class</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; options.UseInMemoryDatabase("dbname"));
      services.AddMvc();
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <blockquote>
    <p>Here is the full project on GitHub to reproduce the issue : <a href="https://github.com/touseefbsb/aspnet_post" rel="nofollow noreferrer">https://github.com/touseefbsb/aspnet_post</a></p>
  </blockquote>
  
  <p>When I enter more than 10 characters, it never hits the breakpoint in postasync method, and nothing happens on the page as well, it is supposed to show me the validation error on UI but it does not.</p>
  
  <p>When I enter a name less than 10 character and press submit, it tries to submit ( the breakpoint in postasync is hit ) but then it tried to redirect, I get following page of error : </p>
  
  <p><a href="https://i.stack.imgur.com/7wqc6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7wqc6.png" alt="error stacktrace"></a></p>
  
  <p><strong>Full StackTrace</strong> : </p>
  
  <pre><code>Microsoft.AspNetCore.Mvc.Internal.RedirectToPageResultExecutor.Execute(ActionContext context, RedirectToPageResult result)
  Microsoft.AspNetCore.Mvc.RedirectToPageResult.ExecuteResult(ActionContext context)
  Microsoft.AspNetCore.Mvc.ActionResult.ExecuteResultAsync(ActionContext context)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+&lt;InvokeResultAsync&gt;d__19.MoveNext()
  System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+&lt;InvokeNextResultFilterAsync&gt;d__24.MoveNext()
  System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+&lt;InvokeNextResourceFilter&gt;d__22.MoveNext()
  System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+&lt;InvokeFilterPipelineAsync&gt;d__17.MoveNext()
  System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+&lt;InvokeAsync&gt;d__15.MoveNext()
  System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  Microsoft.AspNetCore.Builder.RouterMiddleware+&lt;Invoke&gt;d__4.MoveNext()
  System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+&lt;Invoke&gt;d__7.MoveNext()
  </code></pre>