我的验证无效。我有两个文本框,有人可以用来添加“评论”。第一个要求是,如果您尝试添加评论但未提供姓名,则会显示消息“您没有输入您的姓名!”应该弹出。
var urlMatchingRegex = /[:,\s]\s*url\s*\(\s*(?:'(\S*?)'|"(\S*?)"|((?:\\\s|\\\)|\\\"|\\\'|\S)*?))\s*\)/gi;
myStylesheetString.replace(urlMatchingRegex, function(fullMatch, url) {
//Replacement handler
});
以下是视图的代码:
public class Review
{
public int Id { get; set; }
public string ApplicationUserId { get; set; }
[Required(ErrorMessage = "You didn't type your name!")]
public string Name { get; set; }
[Required(ErrorMessage = "You didn't type anything!")]
[MaxLength( 200, ErrorMessage = "Review is too long.")]
public string Reviews { get; set; }
}
最后这是我在API控制器中使用的代码:
<div class="container">
<ul>
<li ng-repeat="review in controller.reviews">
{{review.name}} <br />
{{review.reviews}}
<span ng-show="account.getClaim('IsAdmin') || account.isLoggedIn()">
<a href="/editReview/{{review.id}}">Edit</a>
</span>
<span ng-show="account.getClaim('IsAdmin') || account.isLoggedIn()">
<a ng-click="controller.delete(review.id)">Delete</a>
</span>
</li>
</ul>
<form ng-submit="controller.save()">
<div>
<label>Name:</label>
<input type="text" ng-model="controller.newReview.name" />
</div>
<div>
<label>Review:</label>
<input type="text" ng-model="controller.newReview.reviews" />
</div>
<span ng-show="account.getClaim('IsAdmin') || account.isLoggedIn()">
<input type="submit" value="Submit"/>
</span>
</form>
</div>
当我运行代码并尝试使用名称和正文创建评论时,它会创建评论。但是,如果我在没有名称的情况下尝试这样做,则控制台中会弹出500错误。
任何建议都会非常有用!