PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 4ms RepoModel.GetById 2ms 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
 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
22using System.Web.Mvc;
23using System.Web.Mvc.Html;
24using Bifrost.Commands;
25
26namespace Bifrost.Web.Mvc.Commands
27{
28    /// <summary>
29    /// Represents a <see cref="MvcForm"/> specific for Commands
30    /// </summary>
31    /// <typeparam name="T">Type of command the form is for</typeparam>
32	public class CommandForm<T> : MvcForm
33		where T : ICommand, new()
34	{
35
36        /// <summary>
37        /// Initializes a new instance of <see cref="CommandForm{T}"/>
38        /// </summary>
39        /// <param name="viewContext"><see cref="ViewContext"/> the <see cref="CommandForm{T}"/> should be in</param>
40		public CommandForm(ViewContext viewContext)
41			: base(viewContext)
42		{
43			var viewDataContainer = new CommandViewDataContainer(viewContext);
44
45			Command = new T();
46			viewDataContainer.ViewData.Model = Command;
47
48			Html = new HtmlHelper<T>(viewContext, viewDataContainer);
49		}
50
51        /// <summary>
52        /// Gets the Html helper for the form
53        /// </summary>
54		public HtmlHelper<T> Html { get; private set; }
55
56        /// <summary>
57        /// Gets the Command for the form
58        /// </summary>
59		public T Command { get; private set; }
60	}
61}