利用资源,在MVC中的错误信息

编程入门 行业动态 更新时间:2024-10-23 11:24:09
本文介绍了利用资源,在MVC中的错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从资源得到错误信息。当I C $ CS试图$下面我把这个错误:的属性参数必须是常量前pression,属性参数类型的typeof前pression或数组创建前pression我能怎么办?

公共类UserLoginModel{     [必需的(=的ErrorMessage Resources.PageResources.enterYourEmail)     公共字符串电子邮件{搞定;组; }     [必需的(=的ErrorMessage Resources.PageResources.enterPassword)     公共字符串密码{搞定;组;}

解决方案

试试这个

[必需的(ErrorMessageResourceType = typeof运算(Resources.Resources)            ErrorMessageResourceName =enterYourEmail)] 公共字符串电子邮件{搞定;组; } [必填(ErrorMessageResourceType = typeof运算(Resources.Resources)            ErrorMessageResourceName =enterPassword)] 公共字符串密码{搞定;组;

I want to get error message from resources. When i tried codes below i take that error:"An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type" What can i do ?

public class UserLoginModel { [Required(ErrorMessage =Resources.PageResources.enterYourEmail)] public String Email{ get; set; } [Required(ErrorMessage =Resources.PageResources.enterPassword)] public String Password { get; set; }

解决方案

Try this

[Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "enterYourEmail")] public String Email{ get; set; } [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "enterPassword")] public String Password { get; set;

更多推荐

利用资源,在MVC中的错误信息

本文发布于:2023-11-03 20:18:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误信息   资源   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!