PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Bifrost.Web.Mvc/Commands/CommandForm.cs

#
C# | 61 lines | 22 code | 6 blank | 33 comment | 0 complexity | 35ee6d70a4c174342d8aaece1c6aeb02 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. #region License
  2. //
  3. // Copyright (c) 2008-2012, DoLittle Studios and Komplett ASA
  4. //
  5. // Licensed under the Microsoft Permissive License (Ms-PL), Version 1.1 (the "License")
  6. // With one exception :
  7. // Commercial libraries that is based partly or fully on Bifrost and is sold commercially,
  8. // must obtain a commercial license.
  9. //
  10. // You may not use this file except in compliance with the License.
  11. // You may obtain a copy of the license at
  12. //
  13. // http://bifrost.codeplex.com/license
  14. //
  15. // Unless required by applicable law or agreed to in writing, software
  16. // distributed under the License is distributed on an "AS IS" BASIS,
  17. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. // See the License for the specific language governing permissions and
  19. // limitations under the License.
  20. //
  21. #endregion
  22. using System.Web.Mvc;
  23. using System.Web.Mvc.Html;
  24. using Bifrost.Commands;
  25. namespace Bifrost.Web.Mvc.Commands
  26. {
  27. /// <summary>
  28. /// Represents a <see cref="MvcForm"/> specific for Commands
  29. /// </summary>
  30. /// <typeparam name="T">Type of command the form is for</typeparam>
  31. public class CommandForm<T> : MvcForm
  32. where T : ICommand, new()
  33. {
  34. /// <summary>
  35. /// Initializes a new instance of <see cref="CommandForm{T}"/>
  36. /// </summary>
  37. /// <param name="viewContext"><see cref="ViewContext"/> the <see cref="CommandForm{T}"/> should be in</param>
  38. public CommandForm(ViewContext viewContext)
  39. : base(viewContext)
  40. {
  41. var viewDataContainer = new CommandViewDataContainer(viewContext);
  42. Command = new T();
  43. viewDataContainer.ViewData.Model = Command;
  44. Html = new HtmlHelper<T>(viewContext, viewDataContainer);
  45. }
  46. /// <summary>
  47. /// Gets the Html helper for the form
  48. /// </summary>
  49. public HtmlHelper<T> Html { get; private set; }
  50. /// <summary>
  51. /// Gets the Command for the form
  52. /// </summary>
  53. public T Command { get; private set; }
  54. }
  55. }