Add formnovalidate to the first button input. And formnovalidate attribute could skip the validation in client side,but could not skip validation in server side. So you could clear model state to skip validation in server side.
Below is a mvc demo, you can refer to it.
Custom.cs:
public class Custom
{
public string name{ get; set; }
public int Id { get; set; }
}
In HomeController.cs:
public IActionResult Submit()
{
return View();
}
[HttpPost]
public IActionResult Submit(Custom custom)
{
if (!ModelState.IsValid)
{
ModelState.Clear();//clear model state to skip validation in server side
return View("Submit");
}
return View("Submit");
}
View:
@model nnnn.Models.Custom
@{
ViewData["Title"] = "Submit";
}
<h1>Submit</h1>
<h4>Custom</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Submit">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="name" class="control-label"></label>
<input asp-for="name" class="form-control" />
<span asp-validation-for="name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Id" class="control-label"></label>
<input asp-for="Id" class="form-control" />
<span asp-validation-for="Id" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" formnovalidate class="btn btn-primary" />
<input type="submit" value="Save" class="btn btn-secondary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
Result:
