Click here to Skip to main content
15,893,368 members
Home / Discussions / C#
   

C#

 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1433-Aug-18 11:16
indian1433-Aug-18 11:16 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming3-Aug-18 12:14
mveRichard Deeming3-Aug-18 12:14 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1433-Aug-18 12:48
indian1433-Aug-18 12:48 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming6-Aug-18 2:05
mveRichard Deeming6-Aug-18 2:05 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1436-Aug-18 6:39
indian1436-Aug-18 6:39 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming6-Aug-18 7:15
mveRichard Deeming6-Aug-18 7:15 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1436-Aug-18 7:32
indian1436-Aug-18 7:32 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming6-Aug-18 9:16
mveRichard Deeming6-Aug-18 9:16 
I don't know what to suggest. I've tested the code, and it works. Confused | :confused:

If you're not putting a static StringLength attribute on the property, you'll need to the if (model.CodeLength != 0) block outside of the if (stringLength != null) block:
C#
if (stringLength != null)
{
    newAttributes.Remove(stringLength);
}

if (model.CodeLength != 0)
{
    newAttributes.Add(new StringLengthAttribute(model.CodeLength)
    {
        MinimumLength = model.CodeLength,
        ErrorMessage = @"The field {{0}} length must be at least {model.CodeLength}."
    });
}

attributes = newAttributes;

But if you're never seeing a value in metadata.PropertyName, then there's something else going on.

I assume you have actually enabled unobtrusive validation?



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1436-Aug-18 10:12
indian1436-Aug-18 10:12 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming7-Aug-18 1:56
mveRichard Deeming7-Aug-18 1:56 
QuestionWhen inputting data form main one other always on form main ? Pin
Member 24584672-Aug-18 21:29
Member 24584672-Aug-18 21:29 
AnswerRe: When inputting data form main one other always on form main ? Pin
Richard MacCutchan2-Aug-18 21:40
mveRichard MacCutchan2-Aug-18 21:40 
AnswerRe: When inputting data form main one other always on form main ? Pin
OriginalGriff2-Aug-18 21:45
mveOriginalGriff2-Aug-18 21:45 
GeneralRe: When inputting data form main one other always on form main ? Pin
Member 24584675-Aug-18 16:42
Member 24584675-Aug-18 16:42 
GeneralRe: When inputting data form main one other always on form main ? Pin
OriginalGriff5-Aug-18 19:35
mveOriginalGriff5-Aug-18 19:35 
AnswerRe: When inputting data form main one other always on form main ? Pin
BillWoodruff3-Aug-18 2:17
professionalBillWoodruff3-Aug-18 2:17 
QuestionC# Pin
Jeremiah Okoduwa2-Aug-18 0:51
Jeremiah Okoduwa2-Aug-18 0:51 
AnswerRe: C# Pin
Daniel Pfeffer2-Aug-18 1:12
professionalDaniel Pfeffer2-Aug-18 1:12 
AnswerRe: C# Pin
Nathan Minier2-Aug-18 1:14
professionalNathan Minier2-Aug-18 1:14 
AnswerRe: C# Pin
OriginalGriff2-Aug-18 1:19
mveOriginalGriff2-Aug-18 1:19 
AnswerRe: C# Pin
Richard MacCutchan2-Aug-18 1:33
mveRichard MacCutchan2-Aug-18 1:33 
AnswerRe: C# Pin
BillWoodruff3-Aug-18 2:23
professionalBillWoodruff3-Aug-18 2:23 
QuestionCombining TreeView and Canvas in WPF ( MVVM ) Pin
Kenneth Haugland30-Jul-18 21:50
mvaKenneth Haugland30-Jul-18 21:50 
AnswerRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Pete O'Hanlon30-Jul-18 23:47
mvePete O'Hanlon30-Jul-18 23:47 
GeneralRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Kenneth Haugland31-Jul-18 2:05
mvaKenneth Haugland31-Jul-18 2:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.