Skip to content

Instantly share code, notes, and snippets.

@doggy8088
Last active January 8, 2018 15:16
Show Gist options
  • Save doggy8088/58dd3c773ef9877155b19ebb2fda8525 to your computer and use it in GitHub Desktop.
Save doggy8088/58dd3c773ef9877155b19ebb2fda8525 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Web.Mvc;
using WebApplication1.Models;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
var data = new List<Person>();
data.Add(new Person() { Id = 1, Name = "Will" });
data.Add(new Person() { Id = 2, Name = "Tom" });
data.Add(new Person() { Id = 3, Name = "Mary" });
return PartialView(data);
}
}
}
namespace WebApplication1.Models
{
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
}
@using WebApplication1.Models
@model IEnumerable<Person>
<html>
<body>
<p>
Field name of the first record:@Html.NameFor(m => m.First().Name)<br />
</p>
@{
var data = Model.ToArray();
}
@using (Html.BeginForm())
{
<ol>
@for (var i = 0; i < data.Length; ++i)
{
<li>
@Html.DisplayNameFor(m => m.Name):
@Html.TextBoxFor(m => data[i].Name)
( Field Name: @Html.NameFor(m => data[i].Name) )
</li>
}
</ol>
}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment