【发布时间】:2014-09-01 20:42:42
【问题描述】:
一段时间以来,我一直在使用客户端和服务器端验证助手(如下所示)来验证我网站上的表单。但是,我现在有一个页面,上面有 2 个表单,我不太确定如何(或者是否有可能)单独验证每个表单?
这是我为单个表单所做的:
// Setup validation
Validation.Add("PropertyName",
Validator.Required("Please provide a property name"),
Validator.StringLength(40, 0, "Your property name must be a maximum of 40 characters")
);
Validation.Add("PropertyType",
Validator.Required("Please select a property type"),
Validator.Integer("Please use the options provided")
);
if (IsPost){
if (Validation.IsValid()) {
var sql = "INSERT INTO Property_Info (PropertyName, PropertyTypeID) VALUES (@0, @1)";
db.Execute(sql, Request["PropertyName"], Request["PropertyType"]);
Response.Redirect("~/owner/listings/complete/" + rPropertyId);
} else {
ModelState.AddFormError("broken again!!!!!!!!");
}
}
【问题讨论】:
-
你说你有两张表格是什么意思?在 ASP.NET WebForms 中,只有一种表单。
-
我想在同一个页面上有2个表单,可以独立提交。
-
@MatthewatCriticalCognition 这是 ASP.NET 网页框架的一个示例 - 不是 Web 窗体。
标签: jquery asp.net validation webmatrix asp.net-webpages