Im developing a ASP .NET project. In that project i need a facility to annotate an image, ie Uploading an image and annotate some part on that image. Which is the easiest way to develop that all things....
I've just installed MVC 3 and have the following problem. Even if I try to run the sample project, that is included in MVC 3 installation, when I go to the Register form, only the Required attribute causes validation. The Email Format attribute doesn't work,which means I can enter non-email string into the email field and it submits the form without any error messages.
i have a field username which i want to have as a label in the edit.aspx and as a typical textbox in create.aspx . i have applied datannotation class . how would i do that. in the edit mode it is always going model.isvalid ==false . so what i did had a textbox there with the label and hid it . it is working fine now . but is there any clean way this is done in dataannotation
Has anyone extended the Range attribute to be able to have a variable range?I have a similar need but I can't make this work:
public class YearRangeAttribute : RangeAttribute { public YearRangeAttribute() : base(typeof(DateTime), DateTime.Now.AddYears(-100).Year.ToString(), DateTime.Now.AddYears(-14).Year.ToString()) { } }
There is nothing on the page when it is rendered to the browser and the code above doesn't work.
Technically I have the Data Annoations working with Linq to SQL classes - the problem is when validation passes. When UpdateModel() tries to do its thing i can an error:The model of type 'MyProject.Models.Employee' could not be updated.What i did was i created a partial class for Employee (that is generated by linq to sql), then stuck a Meta Data class on top of it for the validation
Wanting to create custom data annotation validation. Are there any useful guides / samples on how to create them?
Firstly: StringLength with minimum and maximum length. I'm aware .NET 4 can do this, but want to do the same in .NET 3.5, if possible being able to define minimum length only (at least x chars), maximum length only (up to x chars), or both (between x and y chars).
Secondly: Validation using modulus arithmetic - if the number is a valid length, I wish to validate using the Modulus 11 algorithm (I have already implemented it in JavaScript, so I guess it would just be a simple porting?)
Update: Solved second problem, was just a case of copying over the JavaScript implementation and making a few tweaks, so don't need a solution for that.
I am using a model but as I want to have clean views I use the viewmodel approach which is like a downsized model which I map in my controller actions before sending to the view or getting it back in a HttpPost attributed action.
My question is: where to put the data annotation attributes. On the viewmodel classes or on the model? If I get it clearly the viewmodel annotations are used for the client side generation of validation right?
Do does that mean I have to put data annotations everywhere on both model and viewmodel?
I have custom class level validation attribute, inheriting from ValidationAttribute, on my model.
How come it doesn't register a key in the ModelState when its IsValid is false? I can see the the error message in the ModelState.Values collection, but the ModelState.Keys collection only shows an empty string "". Can I provide a key for it - presumably this is because its not assigned to a property?
I wanna be able to use ModelState.Remove in my controller to remove this error upon a certain condition, but I have no Key!
Something is wrong in ASP.NET MVC 2 on client side validation. If I have form for create records in database and all fields are required, validation is triggered only then when I write something in field and delete it. If I go to field, stay this field empty and press Tab key validation isn't triggered.
Here somebody else write about the same problem: [URL]
I have found hints that MVC 2 recognises the 'buddy class' type of property metadata, where data annotation attributes are applied to a 'buddy' metadata class, and the MetadataType on the actual entity class points to that buddy class, as below. However, as below, it seems the only attribute that makes any difference to the rendered UI is DisplayName. Why are the other attributes like DataType, Required, and ReadOnly not working? I.e. why can I enter text in a read only field? Why do I not get an error when a required field is empty? Why does the DataType attribute have no apparent effect? Why does EditorForModel not include validation messages?
[MetadataType(typeof(CustomerMetadata))] public partial class Customer { public class CustomerMetadata { [ScaffoldColumn(false)] public object CustomerId { get; set; } [DisplayName("CustomerNo.")] [ReadOnly(true)] [Required(AllowEmptyStrings = false, ErrorMessage = "Customer No. is required.")] public object CustomerNo { get; set; } } }
I find behaviour the same whether I use an explicit LabelFor and TextBoxFor for each model property, or a single EditorForModel for the whole model.
So I've eagerly added the System.ComponentModel.DataAnnotations namespace to my model.
I've added things such as:
[Required] [DisplayName("First Name")] public string first_name {get;set;}
I really like these attributes because they save me from having to write custom T4 and/or modify views heavily. This way, I can regenerate a view confident that it will add the display names I want, etc.
The problem comes in when I started building a DataGrid helper inspired by the one in ASP.NET MVC2 unleashed. In this helper, Stephen uses reflection to get at the column headings.
var value=typeOf(T).GetProperty(columnName).GetValue(item,null) ?? String.Empty;
Well, the trouble is I don't want to retrieve the property name. I want to retrieve the value for the DisplayName attribute.
My first attempt at this was to look inside the Attributes property of the PropertyInfo class. Unfortunately, none of the data annotations show up as an attribute.
Is there a way to retrieve the data annotations using reflection?
I am a MVC newbie & am lost in various ways validation can be implemented in my application.
I created a custom model-level data annotation validator attribute, but am unable to display its error message in the view. Basically, I have let's say 5 properties in the Entity class Job (model-level custom attribute called UniqueKeywords defined on it):
1) LoginID: value comes in the URL
2) Title: Required property level attribute defined on it
3) CatID1, CatID2, CatID3 - 3 categoryIDs - these are dropdowns in the view with same list of keywords in all 3.
I want to mandate that the values picked by the user in all 3 category dropdowns should be different.
With reference to the code pasted below, here is the explanation of what happens:
When I submit the form without specifying a title or picking anything from any of the 3 category dropdowns, the validation occurs for the property level Required attribute as well as model level uniquekeywords attribute, but the error is displayed only next to the required field "Title". I can confirm that the custom validation also works by filling in some text in the Title field & then re-posting the form...this re-displays the view, but the error message "Category cannot be duplicated" is not displayed.
I have generated entity framework designer classes . After Generating the designer what is the most nicest and cleanest way to apply data annotation to the properties there . I have 3 classes there
When I click submit, It does the validation on the server side, I kinda like it to validate on the Client instead of taking a trip to the server right away.
I have a validation attribute that inherits from ValidationAttribute. However, the particular usage of this attribute applies to lists only (IEnumerable really). How can I specify the usage of this property to only be used with items that inherit from IEnumerabe?
I Used AsyncFileUpload(one of Ajac Control Toolkit Controls) to Uploading User's Image. this works well. But i want to change the image url of an image contorl to uploaded image url. how can i perform that? I put Image control in a Update Panel:
[Code]....
in C# code I wrote these:
[Code]....
But it does not work. Image is like Previous. Note that ImageOperations.ResizeFromStream() method resizes and saves the image to a specefic folder. actually I should trigger a Postback to Update the Update Panel but How to do that. I usedUpdatePanelNew.Update(); but it does not work!
I have a fileupload control in a contentplaceholder in a masterpage. I have to preview the image whenever I browse an image beside it in an imagecontrol.
My application is running on a different server .So I can't give the filepath of my local system.
Also I don't want to store the image in any location and i'm not supposed to use any session variable to pass it to generic handler.
I am trying to put a default image in an Image control in asp.net and it should show that particular image on the page when no other image is assigned or no image available in Database.
I know how to display an image in gridview from image path in database. Now, I want to display an image in an asp.net image control from image path in database. Can anyone point me to a tutorial? I haven't been able to find one that explains how to do it when I don't know what the image path will be. The images are in the root folder.
Here is this thing which to me looks possible, but when I searched over the net I couldnt find anything.
I want to create a page where I can upload an image using any upload function and then display it. Now after diplaying it I want to select the hotspots for an image map. The coordinates of image map values are stored in a database.
Basically I want that to create image maps and hotspots I dont use any offline software, this work is successfully completed and working perfectly, but i want generate one identification where i click the hot spots position in image or CSS file Generate for user identifications, So how can i solve this problem.
I hope You are clear in that what I am looking for.