1

I have a strange problem with my published asp.net MVC4 Solution. Until now, everything goes well about validation. Then things go wrong only on my published IISTEST server (locally through VS2012 no problem, even 'start without debugging' so bundles are active).

What's wrong? I noticed 2 or 3 things but let's talk about the first one.

I have some client side validation on different textboxes, options, ... One of them does not manage validation anymore on my published server. To check that, I navigate to the page, press F12, click on the textbox and copy the html.

Here is the local version (running through VS2012):

<input name="EmergencyReason" class="input-validation-error" id="EmergencyReason" type="text" data-val="true" hideRow="true" data-val-requiredifloadingtoday="Le champ {0} n'est pas valide." value=""/>

As you can see, there is some validation.

Here is the published version:

<input name="EmergencyReason" id="EmergencyReason" type="text" jQuery17205969379292482464="55" hiderow="true"/>

No more validation. But some of my textboxes have validation, some not.

I noticed everytime I have a textbox which validation does not work anymore I have this: jQuery17205969379292482464 in place of input-validation-error... I have bundling on this solution for script and css. Maybe it can help you to understand.

Any idea? I'm on this problem since half a day so any help is greatly appreciated.

Thanks.

UPDATE ------------------------

After doing some tests locally and manipulating the F12 / 'browser mode' >> IE7 I discover that the jQuery17205969379292482464 appears locally and on server so this is not related to my problem. One thing for sure: some basic client validation like [Required] attributes works. Validation who don't work anymore is as follow:

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class RequiredIfLoadingTodayAttribute : ValidationAttribute, IClientValidatable
{        
    public RequiredIfLoadingTodayAttribute() { }

    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        ///////////////
        // IsLoading //
        ///////////////
        var propertyIsLoadingInfo = validationContext.ObjectType.GetProperty("IsLoading");
        var propertyIsLoadingValue = propertyIsLoadingInfo.GetValue(validationContext.ObjectInstance, null);

        //////////
        // Date //
        //////////
        var propertyDateInfo = validationContext.ObjectType.GetProperty("Date");
        var propertyDateValue = propertyDateInfo.GetValue(validationContext.ObjectInstance, null);

        ////////////////
        // Validation //
        ////////////////
        Boolean isLoading = Convert.ToBoolean(propertyIsLoadingValue);
        DateTime dateLoading = Convert.ToDateTime(propertyDateValue);
        DateTime dateToday = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy"));

        // Validation uniquement pour le chargement
        if (isLoading)
        {
            // Si la date de chargement = date du jour et on a pas de raison indiquée -> déclencher une erreur de validation
            if ((DateTime.Compare(dateLoading, dateToday)==0) && (value==null))
            {
                return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
            }
        }
        return ValidationResult.Success;
    }

    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
    {
        var rule = new ModelClientValidationRule {
            ErrorMessage = this.ErrorMessageString,
            ValidationType = "requiredifloadingtoday"
        };
        yield return rule;
    }
}

And the associated js file:

$.validator.unobtrusive.adapters.add(
    'requiredifloadingtoday', '', function (options) {
        options.rules['requiredifloadingtoday'] = options.params;
        options.message['requiredifloadingtoday'] = options.message;
    });
$.validator.addMethod('requiredifloadingtoday', function (value, element, params) {
    // Cette validation côté client n'est utilisée que sur le tab chargement
    // pour s'assurer qu'une raison est indiquée dans le cas ou la date
    // de chargement est le jour même.
    return (($Date.val() == DateToday) && (value != ''))
}, '');

And the viewModel:

    [RequiredIfLoadingToday()]
    public string EmergencyReason { get; set; }

And the view:

<script type="text/javascript" src="@Url.Content("~/Scripts/Loading/When.js")"></script>

<span class="editor-field">   
     @Html.TextBoxFor(m => m.EmergencyReason, Model.Date != DateTime.Today ? new {hideRow="true"} : null)
 </span> 
 ...

I don't know where is the problem on this a little 'more advanced' validation. Ajax problem?

Mikael Engver
  • 4,078
  • 4
  • 40
  • 51
Bronzato
  • 9,152
  • 21
  • 106
  • 196
  • Did you run your application in Release mode locally to verify if you could reproduce this? You seem to have mentioned in your question that you tried running it without debugging but this doesn't mean at all that bundles will combine and minify your files. This will only happen if you run in Release mode locally. – Darin Dimitrov Feb 10 '13 at 10:09
  • I already try to run with 'debug=false' on my dev machine so bundles are activated and the problem is still there. I updated my question to show more infos. Thanks anyway. – Bronzato Feb 10 '13 at 10:38
  • Compare your web.configs. Check paths are correct for the js file. – leppie Feb 10 '13 at 10:42
  • Regaring to the `jQuery17205969379292482464`. It is a uuid that jquery adds to DOM elements when it needs to interact with them. Here is answer that explains details http://stackoverflow.com/a/7150719/1314859. I doubt it is a source of your problem. – Alexander Manekovskiy Feb 10 '13 at 10:45
  • @leppie: web.config is OK. js is reached from the view (some other script is executed). – Bronzato Feb 10 '13 at 10:50
  • @Alexander: you are right: finally I also think this is not related to my problem. – Bronzato Feb 10 '13 at 10:51
  • @Darin: maybe I was not clear in my response to your comment above. after trying to run in local with 'debug=false' bundles will combine and minify my files AND no problem on local computer. Only get problems on IISTEST server. – Bronzato Feb 10 '13 at 10:53

0 Answers0