Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

LuisActionModelBinder.cs 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  1. namespace LuisActions.Samples.Web
  2. {
  3. using System;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Microsoft.Cognitive.LUIS.ActionBinding;
  7. public class LuisActionModelBinder : DefaultModelBinder
  8. {
  9. public override object BindModel(ControllerContext controllerContext, ModelBindingContext context)
  10. {
  11. HttpRequestBase request = controllerContext.HttpContext.Request;
  12. var type = request.Form["LuisActionType"];
  13. if (!string.IsNullOrWhiteSpace(type))
  14. {
  15. var action = Activator.CreateInstance(Type.GetType(type));
  16. Func<object> modelAccessor = () => action;
  17. context.ModelMetadata = new ModelMetadata(
  18. new DataAnnotationsModelMetadataProvider(),
  19. context.ModelMetadata.ContainerType,
  20. modelAccessor,
  21. action.GetType(),
  22. context.ModelName);
  23. return base.BindModel(controllerContext, context);
  24. }
  25. return null;
  26. }
  27. }
  28. public class LuisActionModelBinderProvider : IModelBinderProvider
  29. {
  30. public IModelBinder GetBinder(Type modelType)
  31. {
  32. if (modelType == typeof(ILuisAction))
  33. {
  34. return new LuisActionModelBinder();
  35. }
  36. return null;
  37. }
  38. }
  39. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...