data-annotations

Custom remote validation attribute throwing error at server side in ASP.NET MVC

五迷三道 提交于 2019-12-08 12:18:52
问题 I am developing an ASP.NET MVC Web Application. In my project I am doing remote validation using data annotation to my view model class. I know default remote attribute does not support server validation. I can validate it again in action method. But I do not want to do that it is violating separation of concerns. So I tried to create custom server client remote validation attribute. I found a code online and I used it. But it is giving me error when server validation is occurred. This is my

CS1061: does not contain a definition for

泪湿孤枕 提交于 2019-12-08 12:00:16
问题 Why I get this error? Of course SelectIssuePriority doesn't exist on my first model. I have add it. Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1061: 'Devcore' does not contain a definition for 'SelectIssuePriority' and no extension method 'SelectIssuePriority' accepting a first argument of type 'Devcore.' could be

Applying [JsonIgnore] to property causes DataAnnotation attributes to be “lost”

自作多情 提交于 2019-12-08 11:52:18
问题 Given the following code: [JsonIgnore] [Display(Name = "Loan Cap")] public virtual string SomeProperty { get; protected set; } When the DataAnnotationsModelMetadataProvider.CreateMetadata is called by ASP.NET MVC to fulfil the following call: @Html.DisplayNameFor(model => model.SomeAttribute) The list of attributes handed to CreateMetadata does not include the [Display] attribute (or the [JsonIgnore] for that matter). If I remove the [JsonIgnore] then the [Display] gets found and passed to

ASP.NET MVC - DisplayFormat attribute

送分小仙女□ 提交于 2019-12-08 11:02:06
问题 In my model i've the MyDate property that has datetime type. I sign the property with the DisplayFormat attribute in this mode: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy hh:mm}")] public DateTime MyDate { get; set; } in my view: ... <%= Html.EditorFor(model => model.Evento.MyDate)%> ... why if the value of property is '2011-05-03 14:47', in my view (into EditorFor) i see '03/05/2011 02.47' ? The DataFormatString is correct! thanks so much for reply Alberto

Model layer dependency on MVC attributes

爱⌒轻易说出口 提交于 2019-12-08 10:42:51
问题 We have an MVC3 project that uses nHibernate; there is a separate model project that contains all the model classes which is used by the repository and service layers. The models make use of data annotations like DisplayAttribute and RequiredAttribute from System.ComponentModel.DataAnnotations. There are also attributes such as RemoteAttribute that are contained in System.Web.Mvc. This of course means that the model project now has a dependency to a particular front end technology. Assuming

MVC 4 custom data annotations read in T4 scaffolding

坚强是说给别人听的谎言 提交于 2019-12-08 09:01:10
问题 Can you create custom data annotations for the model that can be read inside the T4 template for the View like property.Scaffold is read? I would like to add data annotation parameters like Scaffold based on which I would build the view. Thank you 回答1: I wrote a blog post on the solution I came up with for MVC5. I'm posting it here for anyone who comes along: https://johniekarr.wordpress.com/2015/05/16/mvc-5-t4-templates-and-view-model-property-attributes/ Edit: In your entities, decorate

ASP.net MVC Validation on mutiple controls

谁说我不能喝 提交于 2019-12-08 08:47:06
问题 I have a strongly typed view which is bound to a ViewModel, one prupose of which is to capture the customers date of birth. To do this I have a number of fields within the ViewModel, defined as follows: public DateTime DOB {get;set;} public int? DOBDay { get { return _DOBDay; } set { _DOBDay = value; SetDOB(); } } public int? DOBMonth { get { return _DOBMonth; } set { _DOBMonth = value; SetDOB(); } } public int? DOBYear { get { return _DOBYear; } set { _DOBYear = value; SetDOB(); } } public

Generate columnheaders based on the DisplayName attribute?

落花浮王杯 提交于 2019-12-08 07:12:57
问题 When I generate a view from the List template I notice that the names of the columns are not based on the DisplayName() annotation. I know how to edit the list.tt code template but I have no idea how to retrieve the DisplayName attributes from the class properties. 回答1: The common way to get the DisplayName attribute is via reflection. The issue your going to have is .tt templates and reflection don't play nice together. Reflection relies on code being loaded into the AppDomain. Since .tt

ASP.net core MVC 6 Data Annotations separation of concerns

扶醉桌前 提交于 2019-12-08 07:04:46
问题 I want put the Data Annotations Attribute and the IClientValidatable interface in two seperate assemblies to have separation of concerns. One is called Common and the other Comman.Web. These links explain how it works in MVC 5: Keeping IClientValidatable outside the model layer http://www.eidias.com/blog/2012/5/25/mvc-custom-validator-with-client-side-validation Unfortunately in MVC 6 there is no DataAnnotationsModelValidatorProvider.RegisterAdapter( typeof(MyValidationAttribute), typeof

Get table name from TableAttribute Dapper.Contrib

倖福魔咒の 提交于 2019-12-08 05:12:55
问题 I'm using Dapper and Dapper.Contrib to map objects from database. I have a class name where I define table name for this class because it is different from the actual class name. Class: [Table("tblUser")] public class User { public int Id { get; set; } public string Title { get; set; } } How can I get the table name which is set Table data annotation attribute? EDIT: I've used following to get it working var tAttribute = (TableAttribute)typeof(T).GetCustomAttributes(typeof(TableAttribute),