数据注释无法在IIS 7.5和Net 4.6上运行 [英] Data Annotations not working on IIS 7.5 and Net 4.6

查看:58
本文介绍了数据注释无法在IIS 7.5和Net 4.6上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在使用以下  -

I’m using the following  -

Visual Studio 2013版本12更新4

Visual Studio 2013 Version 12 Update 4

净4.6

 

我创建了一个MVC 4应用程序,例如以下类 -

I have created an MVC 4 Application and have the following class for example –

  public

Section

 public class Section

   
{

    {

       
[
HiddenInput (DisplayValue =
)]

  ;      
public
int Id {
get ;
set ; }

 

<跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
[ HiddenInput (DisplayValue =
)]

  ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
public
int SectionId {
get ;
set ; }

 

<跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
[ DataType DataType 。MultilineText)]

   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
[
显示 (Name =
"MySectionDescription" )]

    &NBSP;&NBSP;&NBSP;&NBSP;
public
string SectionDescription {
get ;
set ; }

         }

 

class包含一些数据注释,如上所示。

The class includes some Data Annotations as shown above.

 

当应用程序在Visual Studio中运行时,一切都可以在View Page中正常工作使用数据注释显示此类/模型的字段 - 隐藏"Id"字段,隐藏"SectionId"字段,并将"SectionDescription"字段
显示为多行文本框上面有正确的"MySectionDescription"标签。

When the App is run in Visual Studio, everything works OK in the View Page and the fields of this class/model display as indicated using the Data Annotations – the ‘Id’ field is hidden, the ‘SectionId’ field is hidden, and the ‘SectionDescription’ field is displayed as a multi-line text box with the correct ‘MySectionDescription’ label above it.

 

但是,当我将应用程序部署到服务器时会出现问题。在服务器上运行时,视图页面显示不同 - 就好像类/模型中没有数据注释并且字段全部显示而'SectionDescription'字段
只是一个单行文本框标签'SectionDescription'

However, the problem occurs when I Deploy the App to our Server. When run on the Server, the View Page appears different – It’s as if there are no Data Annotations present in the class/model and the fields are ALL displayed and the ‘SectionDescription’ field is just a single line text box with a label of ‘SectionDescription’

 

服务器安装了Net 4.6 - Windows 2008(IIS 7.5)。

The Server has Net 4.6 installed - Windows 2008 (IIS 7.5).

 

我已经检查了服务器上的App bin文件夹,因为它们应该被包含在内,因为它们作为编译的一部分被复制到bin中 -

I have checked the App bin folder on the Server and the following are included as they should be as they are copied to the bin as part of the Compile –

 

System.ComponentModel.DataAnnotations

System.ComponentModel.DataAnnotations

System.Data.DataSetExtensions

System.Data.DataSetExtensions

System.Web.Razor

System.Web.Razor

 

有没有人知道部署和为什么数据注释不起作用?

Does anybody have an ideas what’s missing with the Deployment and why the Data Annotations are not working?

 

谢谢。

推荐答案

嗨迈克

 

根据您的描述
" 在服务器上运行时,视图页面显示不同 - 就好像在类/模型中没有数据注释出现
并且字段全部显示,'SectionDescription'字段为只有一行文字框,标签为"SectionDescription
"

 

似乎html助手或Razor引擎失败将注释转换为它应该是的html元素。

 

我建议您放置一个"调试器"或使用console.log来记录一些信息在错误
函数的"\ Scripts\jquery.validate.unobtrusive.js"上检查发生了什么,以便在出现错误时查看确切的错误消息。为此,您可以查看以下文章"如何验证工作"部分以获取更多信息。

http://rachelappel.com/2015/03/15/asp-net-mvchow-data-annotations-for-asp- net-mvc-validation-work /

http://rachelappel.com/2015/03/15/asp-net-mvchow-data-annotations-for-asp-net-mvc-validation-work/.

 

原因是,排除了一些基本步骤值得尝试的问题的原因可能是,清除浏览器缓存,尝试另一个服务器,另一个版本的.net框架等。

 

希望它有所帮助!


这篇关于数据注释无法在IIS 7.5和Net 4.6上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆