asp.net-mvc-2 – EditorFor – 传入字典的模型项目的类型为’System.Int32′,但是这个字典需要一个类型为’System.String’的模型项目

我似乎无法弄清楚为什么这不行.我正在使用ASP.NET MVC2,我只是试图通过将这个代码放在/Shared/EditorTemplates/String.ascx来覆盖认的编辑器外观:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<%=Html.TextBox(null,Model,new { @class="Text" }) %>

然后在我的View页面中,我有这样一个类型为Int32的行:

<%: Html.EditorFor(model => model.AppID) %>

由于某些原因,这会导致错误

system.invalidOperationException: The model item passed into the dictionary is of type 'system.int32',but this dictionary requires a model item of type 'System.String'.

我看不出有什么可能是错误的,我的目的很简单.如果类型为Int32,为什么尝试使用编辑器来获取字符串?我也应该提到,我已经超过了编辑一个bool? type(将布尔值渲染为复选框),它在同一页上工作正常.

编辑

好吧,我搜索了很多次,但是我没有看到这篇文章,直到我在“相关”链接中找到它.我想这样会有效,但我仍然认为这是一个令人困惑和不一致的实现:

Asp.net Mvc Display template of String,but now every simple type wants to use it!

解决方法

在kendo ui网格做:
public class BookBean
    {
        [ScaffoldColumn(false)]
        public Int32 Id { set; get; }

        public String Title { set; get; }

        public String Author { set; get; }

        public String Publisher { set; get; }

        [UIHint("Integer")]
        public Int32 Price { set; get; }

        [UIHint("Integer")]
        public Int32 Instore { set; get; }

        [UIHint("Integer")]
        public Int32 GroupId { get; set; }
    }

在共享/ EditorTemplate文件夹中的Integer.ascx中:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int?>" %>

<%: Html.Kendo().IntegerTextBoxFor(m => m)
      .HtmlAttributes(new { style = "width:100%" })
      .Min(int.MinValue)
      .Max(int.MaxValue)
%>

相关文章

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