Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have such a code view:

HTML
@foreach(var request in request_list)
{
<input name="abc[@requst.id]" value="1">
}


How to Send controller?
I try to:

C#
[httpPost]

public ActionResult Edit(string[] abc)


But it does not work.
What can I try?
Thank you!
Posted
Updated 13-Jan-16 5:16am
v2

1 solution

You need to use a for loop and reference the array using an indexor (listData[i]) rather than using a foreach loop. There is an example here

c# - Asp.net razor textbox array for list items - Stack Overflow[^]
 
Share this answer
 
v2
Comments
Member 11919288 14-Jan-16 6:11am    
did not help.
F-ES Sitecore 14-Jan-16 6:50am    
Then you didn't understand it. Just google "bind array to view" and you'll find loads of articles explaining how you do this. Rather than using request.id as an "index" you need to use 0, 1, 2 etc so the names have to be abc[0], abc[1] and so on.
Member 11919288 14-Jan-16 7:47am    
o.k. I Send this way. abc[0],abc[2]... But it always comes to visit as NULL... Thank-you!
F-ES Sitecore 14-Jan-16 8:35am    
@using(Html.BeginForm())
{
for(int i = 0; i < request_list.Count; i++)
{
<input name="abc[@i]" value="1"/>
}

<p>
<input type="submit" value="Submit"/>
</p>
}

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