Click here to Skip to main content
15,904,153 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202325-Nov-23 0:56
j k Nov202325-Nov-23 0:56 
GeneralRe: C# error i dont know where i going wrong it say identifer expected in line 281 Pin
j k Nov202324-Nov-23 23:32
j k Nov202324-Nov-23 23:32 
QuestionUpdate text box from serial data Pin
Iskander1234519-Nov-23 21:41
Iskander1234519-Nov-23 21:41 
AnswerRe: Update text box from serial data Pin
Victor Nijegorodov20-Nov-23 0:18
Victor Nijegorodov20-Nov-23 0:18 
AnswerRe: Update text box from serial data Pin
lmoelleb20-Nov-23 5:44
lmoelleb20-Nov-23 5:44 
AnswerRe: Update text box from serial data Pin
Gerry Schmitz20-Nov-23 6:39
mveGerry Schmitz20-Nov-23 6:39 
AnswerRe: Update text box from serial data Pin
jschell20-Nov-23 7:34
jschell20-Nov-23 7:34 
GeneralRe: Update text box from serial data Pin
Iskander1234520-Nov-23 19:29
Iskander1234520-Nov-23 19:29 
GeneralRe: Update text box from serial data Pin
jschell21-Nov-23 5:21
jschell21-Nov-23 5:21 
QuestionSystem.Data.SQLite.SQLiteException: 'SQL logic error no such table: Incident' Pin
Member 1612194217-Nov-23 3:09
Member 1612194217-Nov-23 3:09 
AnswerRe: System.Data.SQLite.SQLiteException: 'SQL logic error no such table: Incident' Pin
Dave Kreskowiak17-Nov-23 3:25
mveDave Kreskowiak17-Nov-23 3:25 
AnswerRe: System.Data.SQLite.SQLiteException: 'SQL logic error no such table: Incident' Pin
trønderen17-Nov-23 3:46
trønderen17-Nov-23 3:46 
GeneralRe: System.Data.SQLite.SQLiteException: 'SQL logic error no such table: Incident' Pin
Member 1612194217-Nov-23 4:02
Member 1612194217-Nov-23 4:02 
GeneralRe: System.Data.SQLite.SQLiteException: 'SQL logic error no such table: Incident' Pin
Dave Kreskowiak17-Nov-23 5:33
mveDave Kreskowiak17-Nov-23 5:33 
GeneralC# 12: New opportunities for auto-foot-wounding Pin
Richard Deeming16-Nov-23 0:24
mveRichard Deeming16-Nov-23 0:24 
GeneralRe: C# 12: New opportunities for auto-foot-wounding Pin
Richard MacCutchan16-Nov-23 1:11
mveRichard MacCutchan16-Nov-23 1:11 
GeneralRe: C# 12: New opportunities for auto-foot-wounding Pin
jschell16-Nov-23 5:18
jschell16-Nov-23 5:18 
QuestionC#, Winforms, Coding Pin
Hoàng Anh Quốc4-Nov-23 0:00
Hoàng Anh Quốc4-Nov-23 0:00 
AnswerRe: C#, Winforms, Coding Pin
Richard MacCutchan4-Nov-23 0:11
mveRichard MacCutchan4-Nov-23 0:11 
AnswerRe: C#, Winforms, Coding Pin
Andre Oosthuizen10-Nov-23 6:28
mveAndre Oosthuizen10-Nov-23 6:28 
QuestionHow to customize the default error message "The value '' is invalid" for dynamically generated form Pin
Fokwa Divine1-Nov-23 4:30
Fokwa Divine1-Nov-23 4:30 
AnswerRe: How to customize the default error message "The value '' is invalid" for dynamically generated form Pin
Richard Deeming1-Nov-23 5:47
mveRichard Deeming1-Nov-23 5:47 
The problem is, you're validating the Units_Service property, not the individual items within it.

And applying a regular expression validation to anything other than a string property makes no sense.

Probably the simplest option would be to create a viewmodel for each item in the list - for example:
C#
public class UnitsServiceViewModel
{
    [Required(ErrorMessage = "You must enter a value.")]
    [RegularExpression("^[0-9]*$", ErrorMessage = "The value must be numeric.")]
    public string Value { get; set; }
}

public class OuterViewModel
{
    public List<UnitsServiceViewModel> Units_Service { get; set; }
    
    internal List<int> Units_Service_Parsed
    {
        get
        {
            if (Units_Service is null) return null;
            
            List<int> value = new(Units_Service.Count);
            foreach (UnitsServiceViewModel vm in Units_Service)
            {
                int.TryParse(vm.Value, out int i);
                value.Add(i);
            }
            
            return value;
        }
        set
        {
            if (value is null)
            {
                Units_Service = null;
            }
            else
            {
                List<UnitsServiceViewModel> list = new(value.Count);
                foreach (int i in value)
                {
                    list.Add(new() { Value = i.ToString() });
                }
                
                Units_Service = list;
            }
        }
    }
}
Razor
@for (int i = 0; i < Model.Units_Service.Count; i++)
{
    <div class="row">
        <div class="col-md-3">
            @Html.LabelFor(model => model.Units_Service[i].Value, Model.Workload_Category_Name[i])
        </div>
        <div class="col-md-4">
            @Html.TextBoxFor(model => model.Units_Service[i].Value, new { style = "width: 15%", MaskedTextBox = "9999", inputmode = "numeric" })
            @Html.ValidationMessageFor(model => model.Units_Service[i].Value)
        </div>
    </div>
}




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

GeneralRe: How to customize the default error message "The value '' is invalid" for dynamically generated form Pin
Fokwa Divine1-Nov-23 8:51
Fokwa Divine1-Nov-23 8:51 
AnswerRe: How to customize the default error message "The value '' is invalid" for dynamically generated form Pin
jschell2-Nov-23 4:30
jschell2-Nov-23 4:30 
GeneralRe: How to customize the default error message "The value '' is invalid" for dynamically generated form Pin
Fokwa Divine3-Nov-23 6:34
Fokwa Divine3-Nov-23 6:34 

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.