如何访问 Html.ValidationMessage() 的文本以在 Razor 中检查它?
How can I access the text of Html.ValidationMessage() to check it in Razor?
我有一些预订电影票的代码。如果有人已经订票,他可以订更多的票,只有在有特定的错误信息时。
此 var validationSummary 仅接收标签 (<span class="field-validation-valid" data-valmsg-for="Saving" data-valmsg-replace="true"></span>
)。但是在网页中@validationSummary 打印出正确的消息。
我如何访问错误消息的文本以进行检查?
@{
@Html.ValidationSummary(true)
var validationSummary = Html.ValidationMessage("Saving");
bool buyAnotherVal = validationSummary.ToString().Contains("By continuing this form, you will booking another some tickets");
}
@using ( Html.BeginUmbracoForm<MovieBookingSurfaceController>( "SubmitBuyerDetails", new { buyAnother = buyAnotherVal }) )
{
@validationSummary
我这样解决了这个问题:
@Html.ValidationSummary(true)
var validationSummary = Html.ValidationMessage("Saving");
bool bookAnotherVal = Html.ValidationSummary().ToString().Contains(BookingException.Msg_EmailDuplicatedBookAnother);
ValidationSummary 方法在页面上显示所有验证消息的列表。 (https://msdn.microsoft.com/en-us//library/system.web.mvc.html.validationextensions.validationsummary(v=vs.118).aspx)
我有一些预订电影票的代码。如果有人已经订票,他可以订更多的票,只有在有特定的错误信息时。
此 var validationSummary 仅接收标签 (<span class="field-validation-valid" data-valmsg-for="Saving" data-valmsg-replace="true"></span>
)。但是在网页中@validationSummary 打印出正确的消息。
我如何访问错误消息的文本以进行检查?
@{
@Html.ValidationSummary(true)
var validationSummary = Html.ValidationMessage("Saving");
bool buyAnotherVal = validationSummary.ToString().Contains("By continuing this form, you will booking another some tickets");
}
@using ( Html.BeginUmbracoForm<MovieBookingSurfaceController>( "SubmitBuyerDetails", new { buyAnother = buyAnotherVal }) )
{
@validationSummary
我这样解决了这个问题:
@Html.ValidationSummary(true)
var validationSummary = Html.ValidationMessage("Saving");
bool bookAnotherVal = Html.ValidationSummary().ToString().Contains(BookingException.Msg_EmailDuplicatedBookAnother);
ValidationSummary 方法在页面上显示所有验证消息的列表。 (https://msdn.microsoft.com/en-us//library/system.web.mvc.html.validationextensions.validationsummary(v=vs.118).aspx)