|
9 | 9 | using DotVVM.Framework.Compilation.Javascript.Ast;
|
10 | 10 | using DotVVM.Framework.Configuration;
|
11 | 11 | using DotVVM.Framework.Utils;
|
| 12 | +using FastExpressionCompiler; |
12 | 13 | using Newtonsoft.Json;
|
13 | 14 |
|
14 | 15 | namespace DotVVM.Framework.Controls
|
@@ -263,18 +264,26 @@ options.KoContext is object ?
|
263 | 264 |
|
264 | 265 | string SubstituteArguments(ParametrizedCode parametrizedCode)
|
265 | 266 | {
|
266 |
| - return parametrizedCode.ToString(p => |
267 |
| - p == JavascriptTranslator.CurrentElementParameter ? options.ElementAccessor : |
268 |
| - p == CommandBindingExpression.CurrentPathParameter ? CodeParameterAssignment.FromIdentifier(getContextPath(control)) : |
269 |
| - p == CommandBindingExpression.ControlUniqueIdParameter ? uniqueControlId?.GetParametrizedJsExpression(control) ?? CodeParameterAssignment.FromLiteral("") : |
270 |
| - p == JavascriptTranslator.KnockoutContextParameter ? knockoutContext : |
271 |
| - p == JavascriptTranslator.KnockoutViewModelParameter ? viewModel : |
272 |
| - p == CommandBindingExpression.OptionalKnockoutContextParameter ? optionalKnockoutContext : |
273 |
| - p == CommandBindingExpression.CommandArgumentsParameter ? options.CommandArgs ?? default : |
274 |
| - p == CommandBindingExpression.PostbackHandlersParameter ? CodeParameterAssignment.FromIdentifier(getHandlerScript()) : |
275 |
| - p == CommandBindingExpression.AbortSignalParameter ? abortSignal : |
276 |
| - default |
277 |
| - ); |
| 267 | + try |
| 268 | + { |
| 269 | + return parametrizedCode.ToString(p => |
| 270 | + p == JavascriptTranslator.CurrentElementParameter ? options.ElementAccessor : |
| 271 | + p == CommandBindingExpression.CurrentPathParameter ? CodeParameterAssignment.FromIdentifier(getContextPath(control)) : |
| 272 | + p == CommandBindingExpression.ControlUniqueIdParameter ? uniqueControlId?.GetParametrizedJsExpression(control) ?? CodeParameterAssignment.FromLiteral("") : |
| 273 | + p == JavascriptTranslator.KnockoutContextParameter ? knockoutContext : |
| 274 | + p == JavascriptTranslator.KnockoutViewModelParameter ? viewModel : |
| 275 | + p == CommandBindingExpression.OptionalKnockoutContextParameter ? optionalKnockoutContext : |
| 276 | + p == CommandBindingExpression.CommandArgumentsParameter ? options.CommandArgs ?? default : |
| 277 | + p == CommandBindingExpression.PostbackHandlersParameter ? CodeParameterAssignment.FromIdentifier(getHandlerScript()) : |
| 278 | + p == CommandBindingExpression.AbortSignalParameter ? abortSignal : |
| 279 | + default |
| 280 | + ); |
| 281 | + } |
| 282 | + catch (ParametrizedCode.MissingAssignmentException e) when (e.Parameter.Parameter == CommandBindingExpression.CommandArgumentsParameter) |
| 283 | + { |
| 284 | + var returnType = expression.GetProperty<ResultTypeBindingProperty>(ErrorHandlingMode.ReturnNull)?.Type; |
| 285 | + throw new DotvvmControlException(control, $"The binding {expression} of type {returnType?.ToCode(stripNamespace: true) ?? "?"} requires arguments, but none were provided to the KnockoutHelper.GenerateClientPostback method.", innerException: e) { RelatedBinding = expression }; |
| 286 | + } |
278 | 287 | }
|
279 | 288 | }
|
280 | 289 |
|
|
0 commit comments