Click here to Skip to main content
11,584,622 members (66,537 online)
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 430
1 Sergey Alexandrovich Kryukov 367
2 Dave Kreskowiak 260
3 Richard Deeming 220
4 virusstorm 194
0 OriginalGriff 1,703
1 Sergey Alexandrovich Kryukov 1,267
2 Abhinav S 711
3 Dave Kreskowiak 687
4 Suvendu Shekhar Giri 568

Advertise | Privacy | Mobile
Web04 | 2.8.150707.1 | Last Updated 8 Apr 2014
Copyright © CodeProject, 1999-2015
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