Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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
@using (Html.BeginForm()) {
        <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>
             <tr >
            @Html.DisplayNameFor(model => model.DevicesForCurrentUser.FirstOrDefault().Name)
             @Html.DisplayNameFor(model => model.DevicesForCurrentUser.FirstOrDefault().State)
@foreach (var item in Model.DevicesForCurrentUser)
      <div class="editor-field">
           @Html.EditorFor(model => item.State)
but I get no results
        public ActionResult Edit(DevicesViewModel collection)
                // TODO: Add update logic here
collection -> DevicesForCurrentUser = null
Posted 21-Nov-12 12:44pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I think you need to specify your post method name to pass your data to server while using MVC.
I think same problem is also posted at below link[^]
Please check.

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

  Print Answers RSS
0 OriginalGriff 6,651
1 Sergey Alexandrovich Kryukov 6,400
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,542

Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 8 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100