0

I'm trying to compare two values of a form. And if they are equal I want to disable the submit button and perhaps display a error field. The focus should be on disabling the button though.

In the code below there is a m.loadingtill and m.loadingfrom field. i would wish to compare these at the button. As you can see I already added some code as how I imagine it could look like. If it has to be done differently, don't mind to do so and explain the how and why.

Can anyone give me insight on how to do this with asp.net with razor 3?

Kind regards

<div class="tf-from-wrapper">
    <span class="tf-title">@AddressGeneric.subtitle_timeframes_from_text</span>
    @Html.TextBoxFor(m => m.LoadingFrom, new { @class = "form-control", id = "loading-from" })
    @Html.ValidationMessageFor(m => m.LoadingFrom, null, new { @class = "text-danger" })
</div>
<div class="tf-till-wrapper">
    <span class="tf-title">@AddressGeneric.subtitle_timeframes_till_text</span>
    @Html.TextBoxFor(m => m.LoadingTill, new { @class = "form-control", id = "loading-till" })
    @Html.ValidationMessageFor(m => m.LoadingTill, null, new { @class = "text-danger" })
</div>

<button type="submit"  class="btn btn-primary btn-nav-unloading" 
@{ 
    if( compare here m.loadingtill == m.loadingfrom) { @:disabled="disabled"
        } } 
>Unloading Address <i class="material-icons">keyboard_arrow_right</i></button>
S B
  • 309
  • 2
  • 9
  • Use a conditional validation attribute, for example a [foolproof](http://foolproof.codeplex.com/) `[NotEqualTo]` attribute so that you get client side and server side validation out of the box –  Jan 19 '18 at 10:00
  • This doesn't do what I asked but it solved what I wanted. Thanks! – S B Jan 19 '18 at 11:09
  • What you asked for was awful :) –  Jan 19 '18 at 11:10

0 Answers0