帮助MVC POST请求 [英] Help for MVC POST request

查看:73
本文介绍了帮助MVC POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。这是我与MVC的第一个项目。我有一个与MVC有关的问题,希望对我有所帮助。我的英语非常糟糕,我道歉。我想更新一个对象但没有得到想要的结果。



这是我当前的viewModel

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


collection -> DevicesForCurrentUser = null

推荐答案

我认为你需要指定你的帖子方法名称,以便在使用MVC时将数据传递给服务器。



我认为同样的问题也发布在下面的链接



http://stackoverflow.com/questions/5247485/httppost-does-not-work-asp-mvc-3 [ ^ ]



请检查。
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.


这篇关于帮助MVC POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆