Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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# ValidateInput跨站点脚本预防不起作用Asp.net MVC_C#_Asp.net Mvc_Cross Site - Fatal编程技术网

C# ValidateInput跨站点脚本预防不起作用Asp.net MVC

C# ValidateInput跨站点脚本预防不起作用Asp.net MVC,c#,asp.net-mvc,cross-site,C#,Asp.net Mvc,Cross Site,验证输入不起作用。表单将被提交,并且即使使用html标记发布表单,也会显示success视图 hello 为什么跨站点脚本预防不起作用?默认情况下应该启用它,对吗 剃须刀视图 <h4 style="color:purple"> <b>ID:</b> @ViewBag.ID <br /> <b>Name:</b> @ViewBag.Name <br /> </h4> <

验证输入不起作用。表单将被提交,并且即使使用html标记发布表单,也会显示
success
视图
hello
为什么跨站点脚本预防不起作用?默认情况下应该启用它,对吗

剃须刀视图

<h4 style="color:purple">
    <b>ID:</b>    @ViewBag.ID <br />
    <b>Name:</b>  @ViewBag.Name <br />   
</h4>
<hr />

@using (Html.BeginForm("register", "Adder", FormMethod.Post))
{
    <div class="form-group">
        @Html.TextArea("comments");
        <input type="submit" />

    </div>
}
更新:

我已经添加了DataAnnotation[Required],现在使用这样的表单。表单仍然提交

@model Vidly.Domain.Player
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section scripts
{

    @Scripts.Render("~/bundles/jqueryval" )

}

@using (Html.BeginForm("register", "Adder", FormMethod.Post))
{
    <div class="form-group">
        @Html.TextBoxFor(m => m.Name,new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.Name)
        <input type="submit" name="submit" />

    </div>
}
@model Vidly.Domain.Player
@{
Layout=“~/Views/Shared/_Layout.cshtml”;
}
@节脚本
{
@Scripts.Render(“~/bundles/jqueryval”)
}
@使用(Html.BeginForm(“register”、“Adder”、FormMethod.Post))
{
@TextBoxFor(m=>m.Name,新的{@class=“form control”})
@Html.ValidationMessageFor(m=>m.Name)
}

这是因为您将参数作为字符串接受,并且在查看页面中没有验证脚本(截至,我们无法查看布局页面是否包含脚本)

请参阅更新。在控制器中的register方法中,将模型作为参数。希望这会有帮助!
@model Vidly.Domain.Player
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section scripts
{

    @Scripts.Render("~/bundles/jqueryval" )

}

@using (Html.BeginForm("register", "Adder", FormMethod.Post))
{
    <div class="form-group">
        @Html.TextBoxFor(m => m.Name,new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.Name)
        <input type="submit" name="submit" />

    </div>
}