Click here to Skip to main content
15,896,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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

C#
<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

C#
[HttpPost]
   public ActionResult Edit(DevicesViewModel collection)
   {

       try
       {
           // TODO: Add update logic here

collection -> DevicesForCurrentUser = null
Posted

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900