Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NET
Hello to all.This is my first project with MVC.I have a question relating to MVC and will hopefully help me. My English is very bad for that I apologize.I want to update an object but not getting the desired result.
 
This is my current viewModel
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; }
    }
}
 
This is my view
 
<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>
            
}
 
but I get no results
 
     [HttpPost]
        public ActionResult Edit(DevicesViewModel collection)
        {
        
            try
            {
                // TODO: Add update logic here
collection -> DevicesForCurrentUser = null
Posted 21 Nov '12 - 12:44


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 355
1 OriginalGriff 330
2 Arun Vasu 264
3 Tadit Dash 221
4 CPallini 203
0 Sergey Alexandrovich Kryukov 10,005
1 OriginalGriff 7,654
2 CPallini 4,171
3 Rohan Leuva 3,447
4 Maciej Los 2,974


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid