0

I have some code to booking tickets on movie. If somebody already booked ticket he may book more tickets, only if there is specific error message.

This var validationSummary receives only the tags (<span class="field-validation-valid" data-valmsg-for="Saving" data-valmsg-replace="true"></span>). But in the web page @validationSummary prints correct message. How can I and can I access the text of the error message to check it at all?

@{
    @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
  • Have you want to read `@validationSummary` in client-side? I think you can split message string to create string array and do something with that array by using client-side scripting. – Tetsuya Yamamoto Nov 03 '17 at 09:57
  • @TetsuyaYamamoto, no, I need check it on the server side to get the buyAnotherVal result in the parameters of the SubmitBuyerDetails action – Mikhail Tarasov Nov 03 '17 at 10:00
  • @TetsuyaYamamoto or it called client side if in Razor .cshtml page?:) – Mikhail Tarasov Nov 03 '17 at 11:29

1 Answers1

0

I solved this problem so:

@Html.ValidationSummary(true)
var validationSummary = Html.ValidationMessage("Saving");
bool bookAnotherVal = Html.ValidationSummary().ToString().Contains(BookingException.Msg_EmailDuplicatedBookAnother);

The ValidationSummary method displays a list of all validation messages on the page. (https://msdn.microsoft.com/en-us//library/system.web.mvc.html.validationextensions.validationsummary(v=vs.118).aspx)