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)
%>

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...