Click here to Skip to main content
Rate this: bad
good
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
 
<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:44pm

1 solution

Rate this: bad
good
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
 
http://stackoverflow.com/questions/5247485/httppost-does-not-work-asp-mvc-3[^]
 
Please check.
  Permalink  

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