ASP.NET Core MVC Interview Question #178

How would you prevent duplicate form submissions in an MVC application?

Senior Practical MVC Scenarios & Production Architecture Senior Advanced

Quick Interview Answer

Use the Post/Redirect/Get pattern so a successful POST redirects to a GET page instead of rendering the final page directly. For operations where duplicate execution would be harmful, also use server-side idempotency or uniqueness controls.

Detailed Explanation

Use the Post/Redirect/Get pattern so a successful POST redirects to a GET page instead of rendering the final page directly. For operations where duplicate execution would be harmful, also use server-side idempotency or uniqueness controls.

PRG improves browser behavior but does not guarantee that two POST requests cannot reach the server. Critical payment, order, or booking workflows need server-side duplicate protection.

Code Example

[HttpPost]
public async Task<IActionResult> Create(OrderInputModel model)
{
    var result = await _service.CreateOnceAsync(
        model.RequestId, model);

    return RedirectToAction(
        "Details", new { id = result.Id });
}