dddd
@model WebApplication2.Models.DemoModel
@{
ViewBag.Title = "Demo";
}
<h2>Demo</h2>
<form method="POST" action="/Home/Demo">
@Html.TextBoxFor(m => m.MyDemo)
@Html.TextBoxFor(m => m.MyDemo2)
@Html.TextBoxFor(m => m.list[0].Title)
@Html.TextBoxFor(m => m.list[0].Name)
@Html.ValidationMessageFor(m => m.list[0].Name)
@Html.TextBoxFor(m => m.list[0].CourseList[0].CourseName)
@Html.TextBoxFor(m => m.list[0].CourseList[1].CourseName)
@Html.TextBoxFor(m => m.list[1].Title)
@Html.TextBoxFor(m => m.list[1].Name)
@Html.ValidationMessageFor(m => m.list[1].Name)
@Html.TextBoxFor(m => m.list[1].CourseList[0].CourseName)
@*<div>
<input type="text" name="@Model.list[0].Title" value="" />
<input type="text" name="@Model.list[0].Title" value="" />
</div>*@
<button type="submit">Update children</button>
</form>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
namespace WebApplication2.Models
{
public class DemoModel
{
public string MyDemo { get; set; }
public string MyDemo2 { get; set; }
public IList<Employee> list { get; set; }
}
public class Employee
{
public int Id { get; set; }
[Required(ErrorMessage = "Please enter your name")]
public string Name { get; set; }
public string Title { get; set; }
public IList<Course> CourseList { get; set; }
}
public class Course
{
public int ID { get; set; }
public string CourseName { get; set; }
}
public ActionResult Demo()
{
//Demo demo = new Demo();
return View();
}
[HttpPost]
public ActionResult Demo(DemoModel demo)
{
if (ModelState.IsValid)
{
}
int i = 5;
return View();
}