我在模型上有一个带有DataAnnotation的BeginForm,但它们无法正常工作。
model.cs
public class modelx
{
.....
[Required(AllowEmptyStrings = false, ErrorMessage = "Time_Step is required"]
public String time_step_serialization { get; set; }
.....
{
view.cs
<script text="text/javascript">
function OnSuccess() {
windows.location.href = '@Url.Action(.....);
}
</script>
<table class....>
@using (Ajax.BeginForm(.........., new AjaxOptions()
{
....
OnSuccess="OnSuccess"
}))
{
@Html.ValidationSummary()
<td>
@Html.TextBoxFor(model => model.time_step_serialization)
@Html.ValidationMessageFor(model => model.time_step_serialization)
</td>
.....
</td>
}
</table>
Controller.cs 我不想检查任何服务器端。
我在web.config上设置了正确的配置,我导入了正确的库js:
有什么问题?
在运行时为该字段生成的html是:
<input data-val="true" data-val-required="Time_step is required" id="time_step_serialization" name="time_step_serialization" type="text" value>
<span class="field-validation-valid" data-valmsg-for="time_step_serialization" data_valmsg_replace="true"></span>
答案 0 :(得分:0)
在发送数据之前尝试使用有效。
function save(){
var valid = $("#FormName").valid();
if (!valid) return false;
// post data
}