Issue in reading resource file in Js file when using BundleTable.EnableOptimizations in MVC

82
May 15, 2018, at 6:40 PM

I am using 'jQuery Impromptu' for prompt a user for input, below is the code

$.prompt(Resource.DeleteConfirm, {
  buttons: { 
    [Resource.Res_Option_Yes]: true, 
    [Resource.Res_Option_No]: false 
  },
  submit: function (e, v, m, f) {
    if (!v) {
      return;
    } else {
    }
  }
});

I use a .cshtml file (Resource for reading resource file

<script type="text/javascript">
  var Resource = {
    Res_Option_Yes: '@Resource.res_Option_Yes',
    Res_Option_No: '@Resource.res_Option_No',
    DeleteConfirm: '@Resource.DeleteConfirm'
  };
</script>

When running the application, it will show 'Yes' and 'No' text in buttons in the prompt, but when I enable Optimization (using BundleTable.EnableOptimizations = true) it shows error:

Minification failed. Returning unminified contents.

How can I solve this issue?

Answer 1

The minification failing is as it doesn't like (or possibly understand) the significance of wrapping an inline variable in square brackets so that its value is used as the key of the object.

To fix this, build the object separately and supply it to the buttons property like this:

var buttons = {};
buttons[Resource.Res_Option_Yes] = true;
buttons[Resource.Res_Option_No] = false;
$.prompt(Resource.DeleteConfirm, {
  buttons: buttons,
  submit: function (e, v, m, f) {
    // note the logic you had in here is redundant...
  }
});
READ ALSO
how to get request parameter of patch request

how to get request parameter of patch request

I'm trying to make an AJAX request by PATCH method, but I get error message "Required String parameter 'paymentPassword' is not present"How to bind the paymentPassword parameter? If I change HTTP request method to POST and @PatchMapping to @PostMapping,...

94
SingalR Error during negotiation request

SingalR Error during negotiation request

I've got a project with SignalR and AspNetI'm trying to connect my client (its a cors) and the first request returns 200 code but I'm getting this error in my client side:

62