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 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器