gpt4 book ai didi

c# - 无法将类型 'void' 隐式转换为 'object' asp.net.MVC

转载 作者:太空宇宙 更新时间:2023-11-03 21:02:25 28 4
gpt4 key购买 nike

我是 .NET 的新手,我只是想在客户端实现数据注释验证。为此,我在网上搜索并找到了一些解决方案。关于客户端验证。

https://www.codeproject.com/Articles/556995/ASP-NET-MVC-interview-questions-with-answers

我只是按照这些步骤操作。我的代码=>(在包中包含js文件(WEB.OPTIMIZATION))代码如下---

.Include("~/Content/js/plugins/jquery/jquery-2.2.4.js")
.Include("~/Scripts/jquery.validate.js")
.Include("~/Scripts/jquery.validate.unobtrusive.js")

还有我的看法--

        @using something
@model Vendor
@{
ViewBag.Title = "Add Vendor";
ViewBag.Description = "TSMS-admin";
}

@section PageDescription{
<section class="content-header">
<h1>
@ViewBag.Title
<small>@ViewBag.Description</small>
</h1>
</section>
}

@section Scripts{
@if (ViewBag.Message != null)
{
<script type="text/javascript">
$(function () {
CustomMessage('Error', '@ViewBag.Message', 'Close');
});
</script>
}
}


<div class="row .col">
<div style="margin-top:20px" class="mainbox col-md-12 col-md-offset-0 col-sm-8 col-sm-offset-2">
@using (Html.BeginForm("Add", "Admin", FormMethod.Post, new { @class = "form-horizontal", @id = "AddVendorForm", @enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.EnableClientValidation()
@Html.ValidationSummary(true, null, new { @class = "text-danger" })
@Html.HiddenFor(model => model.adding_date, new { @Value = System.DateTime.Now })

<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Add A New Vendor</div>
</div>
<div class="panel-body col-md-12">
<div>
<img class="center-block" style="border-radius: 3px;height: 200px;width: 200px;" id="venpic" src="~/Content/img/tsms/default/upload.png"><br><br /><br />
<label style="border-radius: 2px;" class="col-xs-12 btn btn-primary btn-load btn-lg" data-loading-text="Uploadinging Picture...">
<input autocomplete="off" required name="pic_path" id="ifile_img" accept="image/gif,image/jpeg,image/jpg" onchange="readURL(this,'#venpic')" type="file" style="display: none;">Choose Pic
</label>
@Html.ValidationMessageFor(model => model.pic_path, null, new { @class = "text-danger" })
</div>
<br /><br /><br />
<div>
@Html.TextBoxFor(model => model.heading, new { @style = "border-radius:3px;", @class = "form-control", @id = "VendorName", @placeholder = Html.DisplayNameFor(model => model.heading), @autocomplete = "on", @onkeyup = "uppercase(this)" })
@Html.ValidationMessageFor(model => model.heading, null, new { @class = "text-danger" })
</div>
<br />
<div>
@Html.TextAreaFor(mode => mode.body, new { @style = "border-radius:3px;", @class = "form-control", @id = "VendorDetails", @placeholder = Html.DisplayNameFor(model => model.body), @autocomplete = "on" })
@Html.ValidationMessageFor(model => model.body, null, new { @class = "text-danger" })
</div>
</div>
<div class="panel-footer">
<div class="panel-title">
<div class="form-actions no-color">
<input onclick="d()" type="button" id="AddVendor" value="Add" class="btn btn-success" /> | @Html.ActionLink("Back to List", "Manage")
</div>
</div>
</div>
</div>
}
</div>
</div>

问题是当我只想添加 @Html.EnableClientValidation() 时,它向我显示如下所示的某种错误...

Problem我怎样才能解决我的问题。还有我在客户端实现数据注释验证所遵循的步骤我是对的/或者我需要其他东西来实现这个---比如@Html.EnableUnobtrusiveJavaScript()有必要实现这个吗....net MVC 专家请帮助我......

最佳答案

您不需要在每个 View 中设置@Html.EnableUnobtrusiveJavaScript()@Html.EnableClientValidation(),只需将它放在您的web.config 中:

<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

希望您已经在模型属性上设置了注释属性。此外,在加载表单后运行以下脚本:

<script>
$(document).ready(function(){
var form = $('form')//Give Id prop to your from
form.removeData("validator")
form.removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse(form);
});
<script>

关于c# - 无法将类型 'void' 隐式转换为 'object' asp.net.MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44127542/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com