Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have number of dates in database. Now i have to edit any date. now i m getting these dates from database. As i don't know how many dates i have in database so i get them dynamically and add here in a loop. i generate the loop of date-pickers. now i want to change only one or two dates rest r same. the problem is i have to extract the value from that particular id which i changed.

What I have tried:

i tried lot from google but getting nothing..
Posted
Updated 12-Sep-17 19:26pm
v2
Comments
Graeme_Grant 12-Sep-17 6:27am    
You know that we can't see your screen from here so we can't see how your controller is wired the the razor page.

Once you are ready update the question with clear and concise details, sample code, any error messages (including inner exception details), etc, please click on Improve question widget to add more info to the question.
Karthik_Mahalingam 12-Sep-17 9:51am    
Not clear, Please add more info

1 solution

The way to handle multiple controls is to ensure they have a naming scheme like

txt[0]
txt[1]
txt[2]

and so on. If your names are like that then MVC model binding will convert the values into an array. The control's id is irrelevant, that is only used for css and javascript

@using (Html.BeginForm())
{
    for (int i=0; i<5; i++)
    {
        @Html.TextBox(string.Format("txtDate[{0}]", i.ToString()), string.Empty, new { id= string.Format("txtDate{0}", i.ToString()) })
    }
    <p><input type="submit" value="Submit"/></p>
}


controller

[HttpPost]
public ActionResult Index(string[] txtDate)
{
            
    return View();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900