How do you get post value in .NET Core

Viewed 24783

I have a Customer controller that has these 2 action methods.

    [HttpGet]
    public IActionResult Create()
    {
        ViewBag.Title = "Customers";
        return View();
    }

    [HttpPost]
    public IActionResult Create(IFormCollection form)
    {
        return View();
    }

I also created a Customer view.

<form class="form-horizontal" method="post" action="/Customer/Create">
    <div class="form-group">
        <label class="col-lg-2 control-label">FirstName *</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" required name="FirstName">
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg-2 control-label">LastName *</label>
        <div class="col-sm-6">
            <input type="text" class="form-control" required name="LastName">
    </div>
</div>
</form>

How do I get the post values? Every time I submit the form it goes to the [HttpGet] and I want to use the [HttpPost]. I'm new to ASP.NET Core so sorry for the simple question.

2 Answers
Related