Skip to content

Instantly share code, notes, and snippets.

<input type="hidden" name="list.Index" value="0" />
[HttpPost]
public ActionResult PostData(List<ItemModel> list)
<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="..." />
@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)
@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))
{
@(Html.Grid(Model.Items)
.RenderUsing(new PostAsListRenderer<ItemModel>("list"))
.Columns(c =>
{
c.Custom(
@<text>
@Html.HiddenFor(x => item.Id)
@item.Id
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;
class ContractListBuilder IViewBuilder<int, List<SelectListItem>>
class LanguageListBuilder IViewBuilder<int, List<SelectListItem>>
@Rookian
Rookian / gist:c30128591f3986e2c38c
Created August 28, 2014 21:12
EF AutoMapper Proxy Tests:
using System.Data.Entity;
using System.Linq;
using AutoMapper;
namespace EFTests
{
public class Program
{
public static void Main()
{
@Rookian
Rookian / gist:7c5f559f9b4e36ca7dbb069d7a675e0a
Last active May 12, 2016 14:18
ViewModel with inheritance
public class ViewModel : InputModel
{
public bool ShowSaveButton { get; set; }
public string Customer { get; set; }
}