asp.net-mvc – MVC简单模型绑定无法正常工作

好吧,这一定是一些愚蠢的东西,我做错了,但我找不到它.

MVC行动:

[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult Create(BatchCreateviewmodel createModel)
{
    return RedirectToRoute(MVC.Home.display());
}

BatchCreateviewmodel:

public class BatchCreateviewmodel
{
    bool searchAVM;
    bool searchBPO;
    bool searchAppraisal;
    int transactionAge;
    string Description;
    string uploadfile;
}

View页面上有一些名为“searchAVM”,“searchBPO”,“searchAppraisal”的控件,(复选框)“transactionAge”(一组带整数值的单选按钮)和“description”(文本框)

当我在“Create”条目处中断时,createModel就在那里,但是具有所有认值(对于字符串为null,对于布尔值为false,对于int为0).如果我检查Request.Form,值就在那里,但它们只是没有进入模型.

我究竟做错了什么?

(这是在MVC 2,框架4下.)

解决方法

您的视图模型应具有自动属性,而不是公共变量.它之前让我感到惊讶!

所以它应该是:

public class BatchCreateviewmodel 
{ 
    public bool searchAVM {get;set;}
    public bool searchBPO {get;set;}
    public bool searchAppraisal {get;set;}
    public int transactionAge {get;set;}
    public string Description {get;set;}
    public string uploadfile {get;set;}
}

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....