asp.Net   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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)
%>

大佬总结

以上是大佬教程为你收集整理的asp.net-mvc-2 – EditorFor – 传入字典的模型项目的类型为’System.Int32′,但是这个字典需要一个类型为’System.String’的模型项目全部内容,希望文章能够帮你解决asp.net-mvc-2 – EditorFor – 传入字典的模型项目的类型为’System.Int32′,但是这个字典需要一个类型为’System.String’的模型项目所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。