SpongeWu 2020-04-01 15:56
浏览 213

ASP MVC Html.BeginForm前台传递整个复杂对象至后台问题

我从后台传递了一个强类型Model到前台显示,然后前台建立一个Html.BeginForm表单,并通过object routeValues将整个Model传回后台,但后台接收不到该对象里面的复杂类型数据,具体代码如下:

Model:

    public class FooterViewModel
    {
        public string CompanyName { get; set; }

        public string Year { get; set; }
    }

    public class BaseViewModel
    {
        public string UserName { get; set; }

        public FooterViewModel FooterData { get; set; }
    }

    public class OperateEmployeeViewModel : BaseViewModel
    {
        public int ID { get; set; }
        .......
        .......
     }

View:

@model MVCExample.ViewModels.OperateEmployeeViewModel

@{
    ViewBag.Title = "DeleteEmployee";
}

<h2>Delete Confirmation</h2>

@using (Html.BeginForm("DeleteEmployee", "Employee", Model, FormMethod.Post))
    {
        <table>
            <tr>
                <td>
                    First Name:
                </td>
                <td>
                    @Html.DisplayFor(x => x.FirstName)
                </td>
            </tr>
           ......
    }

Controller:

public ActionResult DeleteEmployee(OperateEmployeeViewModel operateEmployee, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
                case "Delete":
                    Employee e = new Employee();
                    .........
                    .........
                    return RedirectToAction("Index");
                case "Cancel":
                    return RedirectToAction("Index");
            }
            return new EmptyResult();
        }

图片说明

图片说明

打了断点,可以看到从后台其他action传递到前台的强类型Model中,FooterData数据不是null的,但从前台beginform传递到后台,action接收到的FooterData却是null,请问这是怎么回事,要怎么解决?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答