客户端验证未执行MVC 4

本文关键字:MVC 执行 验证 客户端 | 更新日期: 2023-09-27 18:29:41

布局

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <!-- Apple devices fullscreen -->
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <!-- Apple devices fullscreen -->
    <meta names="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <title>New Indus Goods - Loagin</title>
    <link rel="stylesheet" type="text/css" href="@Url.Content("~/css/bootstrap.min.css")"/>
     <link rel="stylesheet" type="text/css" href="@Url.Content("~/css/plugins/icheck/all.css")"/>
    <link rel="stylesheet" type="text/css" href="@Url.Content("~/css/style.css")"/>
    <link rel="stylesheet" type="text/css" href="@Url.Content("~/css/themes.css")"/>
     <link href="@Url.Content("~/Styles/view_specific_style.css")" rel="stylesheet" type="text/css" />
   <script type="text/javascript" src="@Url.Content("~/js/jquery.min.js")"></script>

    <script type="text/javascript" src="@Url.Content("~/js/plugins/nicescroll/jquery.nicescroll.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/js/plugins/validation/jquery.validate.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/js/plugins/validation/additional-methods.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/js/plugins/icheck/jquery.icheck.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/js/bootstrap.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/js/eakroko.js")"></script>
    <!--[if lte IE 9]>
        <script type="text/javascript" src="@Url.Content("~/js/plugins/placeholder/jquery.placeholder.min.js")"></script>
        <script>
            $(document).ready(function() {
                $('input, textarea').placeholder();
            });
        </script>
    <![endif]-->
    <!-- Favicon -->
    <link rel="shortcut icon" href="~/img/favicon.ico" />
    <!-- Apple devices Homescreen icon -->
    <link rel="apple-touch-icon-precomposed" href="~/img/apple-touch-icon-precomposed.png" />
</head>
<body class='login'>
    <div class="wrapper">
        <h1>
            <a href="index.html">
                <img src="@Url.Content("~/img/logo-big.png")" alt="" class='retina-ready' width="59" height="49">New Indus Goods</a>
        </h1>
        <div id="body" class="login-body">
        @RenderSection("featured",required:false)
            <section class="content-wrapper">
            @RenderBody()
            </section>

        </div>
    </div>
</body>
</html>

查看

@model Test1.Models.UserProfile
@{
      Layout = "~/Views/_LayoutPage1.cshtml";
    ViewBag.Title = "Index";
    Test1.Models.UserProfile lol = ViewBag.Profile;
}
@section featured
{
@using (Html.BeginForm("Index", "Input"))
{
@Html.ValidationSummary(true)
<fieldset>
<div class="content-wrapper">
    <div class="form-group">
                    <div class="email controls">
                       @Html.EditorFor(model => model.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Name)
                    </div>
                </div>
</div>

<p>lol what is is</p>
</fieldset>
  <p>
            <input type="submit" value="Save" />
        </p>
}
}
<div>
@Html.ActionLink("Back To Index", "Index");
</div>

服务器端验证已执行,但客户端未执行!请告诉我我在这里少了什么??我曾尝试在谷歌上找到解决方案,但失败了。我是MVC的新手,所以请帮帮我!页面返回POST,然后返回并说Name字段是必需的,为什么在返回POST之前不进行验证??

客户端验证未执行MVC 4

我不得不添加

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

也在与页面相关的web.config中:)