Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
SitecoreExtensions/Framework/Sitecore.Extensions/Mvc/TempDataModelBinder.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
41 lines (38 sloc)
1.37 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web.Mvc; | |
namespace Framework.Sc.Extensions.Mvc | |
{ | |
/// <summary> | |
/// Temp data model binder. | |
/// </summary> | |
public class TempDataModelBinder : CustomModelBinderAttribute, IModelBinder | |
{ | |
/// <summary> | |
/// Retrieves the associated model binder. | |
/// </summary> | |
/// <returns> | |
/// A reference to an object that implements the <see cref="T:System.Web.Mvc.IModelBinder" /> interface. | |
/// </returns> | |
public override IModelBinder GetBinder() | |
{ | |
return this; | |
} | |
/// <summary> | |
/// Binds the model to a value by using the specified controller context and binding context. | |
/// </summary> | |
/// <param name="controllerContext">The controller context.</param> | |
/// <param name="bindingContext">The binding context.</param> | |
/// <returns> | |
/// The bound value. | |
/// </returns> | |
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) | |
{ | |
ValueProviderResult val = bindingContext.ValueProvider.GetValue(bindingContext.ModelType.Name); | |
if (val == null) | |
return null; | |
object result = val.RawValue; | |
result = result ?? Activator.CreateInstance(bindingContext.ModelType); | |
return result; | |
} | |
} | |
} |