Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Asp.Net Core 3.1 MVC客户端验证不适用于区域文件夹中的视图_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

C# Asp.Net Core 3.1 MVC客户端验证不适用于区域文件夹中的视图

C# Asp.Net Core 3.1 MVC客户端验证不适用于区域文件夹中的视图,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我正在创建一个ASP.NET Core 3.1 MVC应用程序。我创建了一些逻辑,用户可以在其中创建SellOffer。我想添加一些客户端验证。问题是当我输入无效数据时,什么也没有发生。我做了一些研究,发现它可能与_validationscripttial.cshtml有关。我想要验证的视图位于Areas文件夹中,所以我只是将文件复制到该区域的views文件夹中,但它不起作用。这是我的密码 这就是观点 @model SellOfferDTO @{ ViewData["Title"] =

我正在创建一个ASP.NET Core 3.1 MVC应用程序。我创建了一些逻辑,用户可以在其中创建SellOffer。我想添加一些客户端验证。问题是当我输入无效数据时,什么也没有发生。我做了一些研究,发现它可能与_validationscripttial.cshtml有关。我想要验证的视图位于Areas文件夹中,所以我只是将文件复制到该区域的views文件夹中,但它不起作用。这是我的密码

这就是观点

@model SellOfferDTO

@{
    ViewData["Title"] = "Create";
}

<h1>Create</h1>

<hr />
<div class="row">
    <div class="col-md-4">
        <form asp-action="Create">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="ProductTitle" class="control-label"></label>
                <input asp-for="ProductTitle" class="form-control" />
                <span asp-validation-for="ProductTitle" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="ProductDescription" class="control-label"></label>
                <input asp-for="ProductDescription" class="form-control" />
                <span asp-validation-for="ProductDescription" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="ProductPrice" class="control-label"></label>
                <input asp-for="ProductPrice" class="form-control" />
                <span asp-validation-for="ProductPrice" class="text-danger"></span>
            </div>
            <div class="form-group form-check">
                <label class="form-check-label">
                    <input class="form-check-input" asp-for="PriceIsNegotiable" /> @Html.DisplayNameFor(model => model.PriceIsNegotiable)
                </label>
            </div>
            <div class="form-group form-check">
                <label class="form-check-label">
                    <input class="form-check-input" asp-for="CanReciveBuyOffers" /> @Html.DisplayNameFor(model => model.CanReciveBuyOffers)
                </label>
            </div>
            <div class="form-group">
                <label asp-for="Quantity" class="control-label"></label>
                <input asp-for="Quantity" class="form-control" />
                <span asp-validation-for="Quantity" class="text-danger"></span>
            </div>
            <div class="form-group">
                <input type="submit" value="Save" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>

<div>
    <a asp-action="Index">Back to your Sell Offers</a>
</div>
@model SellOfferDTO
@{
ViewData[“标题”]=“创建”;
}
创造

@DisplayNameFor(model=>model.price可协商) @DisplayNameFor(model=>model.CanReciveBuyOffers) 返回您的销售报价
这是我的DTO。(注意:我计划在成功后添加更多验证属性)

public int Id{get;set;}
[StringLength(999999,ErrorMessage=“产品标题长度必须介于999999和3之间”,最小长度=3)]
公共字符串ProductTitle{get;set;}
公共字符串ProductDescription{get;set;}
公共十进制产品价格{get;set;}
公共十进制总价{get;set;}
公共布尔价格可协商{get;set;}
公共布尔可以接收BuyOffers{get;set;}
公共整数数量{get;set;}
公共字符串TagsStr{get;set;}
公共列表标记{get;set;}
这是_validationscriptial.cshtml

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


因此,我的问题是,客户端验证失败的原因是什么?我找到了一个可行的解决方案。我补充说:

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

对于视图来说,验证似乎工作得很好

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