Skip to content

Instantly share code, notes, and snippets.

class ContractListBuilder IViewBuilder<int, List<SelectListItem>>
class LanguageListBuilder IViewBuilder<int, List<SelectListItem>>
public class PostAsListRenderer<T> : HtmlTableGridRenderer<T> where T : class
{
private readonly string _collectionName;
private string _previousHtmlFieldPrefix;
Guid _currentIndex;
bool _firstCellRendered;
public PostAsListRenderer(string collectionName)
{
_collectionName = collectionName;
@using (Html.BeginForm("PostData", "Home", FormMethod.Post))
{
@(Html.Grid(Model.Items)
.RenderUsing(new PostAsListRenderer<ItemModel>("list"))
.Columns(c =>
{
c.Custom(
@<text>
@Html.HiddenFor(x => item.Id)
@item.Id
@using (Html.BeginForm("PostData", "Home", FormMethod.Post, new { id = "simpleForm" }))
{
@(Html.Grid(Model.Items)
.RenderUsing(new PostAsListRenderer<ItemModel>("list"))
.Columns(c =>
{
c.For(x => Html.Partial("Grid/Id", x)).Named("Id");
c.For(x => Html.Partial("Grid/Name", x)).Named("Name");
c.For(x => Html.Partial("Grid/Description", x)).Named("Description");
c.For(x => Html.Partial("Grid/SelectedItem", new ListModel { SelectedItem = x.SelectedItem, SelectListItems = Model.SelectListItems })).Named("DropDown");
@using (Html.BeginForm("PostData", "Home", FormMethod.Post, new { id = "simpleForm" }))
{
ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "list[0]";
<input type="hidden" name="list.Index" value="0" />
@Html.TextBoxFor(x => x.Name)
@Html.TextBoxFor(x => x.Description)
ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "list[1]";
<input type="hidden" name="list.Index" value="1" />
@Html.TextBoxFor(x => x.Name)
<input type="hidden" name="list.Index" value="0" />
<input type="text" name="list[0].Name" value="Alex" />
<input type="text" name="list[0].Description" value="..." />
<input type="hidden" name="list.Index" value="1" />
<input type="text" name="list[1].Name" value="Chris" />
<input type="text" name="list[1].Description" value="..." />
[HttpPost]
public ActionResult PostData(List<ItemModel> list)
<input type="hidden" name="list.Index" value="0" />
@Rookian
Rookian / interception.cs
Created September 3, 2012 18:40
Dynamic Interception
public class RepositoryInterceptor : IInterceptor
{
private readonly MemoryCache _memoryCache;
public RepositoryInterceptor()
{
_memoryCache = new MemoryCache("repositoryCache");
}
public void Intercept(IInvocation invocation)
@Rookian
Rookian / SerializationExtensions.cs
Created June 6, 2012 11:14
Dictionary Serialization
public static class SerializationExtensions
{
public static string Serialize<T>(this T obj)
{
var serializer = new DataContractSerializer(obj.GetType());
using (var writer = new StringWriter())
using (var stm = new XmlTextWriter(writer))
{
serializer.WriteObject(stm, obj);
return writer.ToString();