using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace SmartHomeMVC.ViewModel { public class DevicesViewModel { public List<Device> DevicesForCurrentUser { get; set; } public Room CurrentRoom { get; set; } } }
<h2>CreateSettings</h2> @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>DevicesViewModel</legend> <h3>Current temp @Model.CurrentRoom.CurrentTemp</h3> <div class="editor-field"> <h3> Target temp @Html.EditorFor(model =>model.CurrentRoom.TargetTemp)</h3> <h3> Termostat @Html.EditorFor(model =>model.CurrentRoom.Termostat) </h3> </div> <table> <tr > <th> @Html.DisplayNameFor(model => model.DevicesForCurrentUser.FirstOrDefault().Name) </th> <th> @Html.DisplayNameFor(model => model.DevicesForCurrentUser.FirstOrDefault().State) </th> <th></th> </tr> </table> @foreach (var item in Model.DevicesForCurrentUser) { @item.Name <div class="editor-field"> @Html.EditorFor(model => item.State) </div> }
[HttpPost] public ActionResult Edit(DevicesViewModel collection) { try { // TODO: Add update logic here
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)