如何使用taghelper在表单验证中不呈现服务器端请求

时间:2017-04-25 03:29:00

标签: asp.net-mvc visual-studio-2015 asp.net-core-mvc asp.net-core-tag-helpers

当我发布以下表单时,它会请求服务器。如何阻止它发布到服务器并使用jquery验证在客户端进行验证?

这是我的代码:

<form asp-controller="Gigs" asp-action="Create" method="post">
<div class="form-group">
   <label asp-for="@Model.Venue"></label>
    <input asp-for="@Model.Venue" class="form-control" />
    <span asp-validation-for="@Model.Venue"></span>
</div>
<div class="form-group">
    <label asp-for="@Model.Date"></label>
    <input asp-for="@Model.Date" class="form-control" />
    <span asp-validation-for="@Model.Date"></span>
</div>
<div class="form-group">
    <label asp-for="@Model.Time"></label>
    <input asp-for="@Model.Time" class="form-control" />
    <span asp-validation-for="@Model.Time"></span>
</div>
<div class="form-group">
    <label asp-for="@Model.Genre"></label>
    <select asp-for="@Model.Genre" asp-items="@(new SelectList(Model.Genres, "Id", "Name"))" class="form-control"><option>Please Select One</option></select>
    <span asp-validation-for="@Model.Genre"></span>
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>

我尝试了这个,但没有工作

<environment names="Development">
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
</environment>   

0 个答案:

没有答案