【发布时间】:2013-10-27 08:49:16
【问题描述】:
我在 model
中有这个类public class Tenant :User
{
[Required]
public string PassportNumber { get; set; }
[Required]
public string image { get; set; }
[Required]
public string passportImage { get; set; }
}
在视图我有这个代码:
@using (Html.BeginForm("RegisterTenant", "Tenant", FormMethod.Post,
new { enctype = "multipart/form-data" })){
<div class="editor-label">
@Html.LabelFor(model => model.FirstName)
</div>
<div class="editor-field">
@Html.TextBoxFor(x => x.FirstName, new {placeholder = "Enter Your First Name" })
@Html.ValidationMessageFor(model => model.FirstName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.LastName)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.LastName, new { placeholder = "Enter Your Last Name"})
@Html.ValidationMessageFor(model => model.LastName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Password)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Password, new { placeholder = "Enter Your Password"})
@Html.ValidationMessageFor(model => model.Password)
</div>
<div class="editor-field">
<label>Password Again</label>
<input type="text" placeholder="Enter your password again" name="Password2"/>
<span class="errorMessage"></span>
</div>
<div class="editor-label">
@Html.LabelFor(model => model.MobileNumber)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.MobileNumber, new { placeholder = "Enter Your Mobile Number"})
@Html.ValidationMessageFor(model => model.MobileNumber)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PassportNumber)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.PassportNumber, new {placeholder = "Enter Your Passport Number"})
@Html.ValidationMessageFor(model => model.PassportNumber)
</div>
<div class="editor-field">
<label for="file">Upload You Passport:</label>
<input type="file" name="file" id="passport" style="width: 100%;" />
<span class="errorMessage"></span>
</div>
<div class="editor-field">
<label for="file">Upload You Image:</label>
<input type="file" name="file" id="image" style="width: 100%;" />
<span class="errorMessage"></span>
</div>
<input type="submit" value="Register" class="submit"/>
}
我的问题
即使我使用了验证消息和required 标签,当我按下提交按钮时,尽管字段为空,它仍然有效。
我做错了什么?
【问题讨论】:
-
只是为了确定,是在谈论客户端还是服务器端验证?
-
您是否在视图中包含了 Jquery 验证文件?
-
@AirL 客户端验证
-
@AbbasAmiri 我用互联网应用程序创建了新的 mvc 4,所以我认为它已经安装了
-
@MarcoDinatsoli 不,您不应该手动操作
标签: asp.net-mvc asp.net-mvc-4 html-helper