1

I am passing a set of controls(checkbox,radio buttons etc) as a list through controller to its corresponding view. Here is what I want to achieve.

  1. Each row in the table should have 3 columns.
  2. If the number of objects are more than 3 then a new row should be created in the table.

I am doing this using MVC 4.

1
  • 2
    In addition to posting your requirements you forgot to show what you have tried so far and what difficulties did you encounter with your code. Right now you sound more like a customer in a restaurant than a software developer asking a specific programming related question on StackOverflow. Commented Mar 19, 2013 at 6:49

1 Answer 1

2

This is the way yo can do it in mvc :

Model:

    public class Class1
    {
          public string numbers { get; set; }
    }

The controller code :

    public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";
            //Sample1--load array data using linq
            List<Class1> model = new List<Class1>();
            int[] numbersdata = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0, 15, 14, 11, 13, 19, 18, 16, 17, 12, 10 };

            var lowNums = from n in numbersdata where n > 5 select n;

            foreach (var x in lowNums)
            {
                model.Add(new Class1()
                {
                    numbers = x.ToString()
                });
            }
            return View(model);
        }

view :

@model IEnumerable<MvcApplication1.Models.Class1>
@using (Html.BeginForm())
{
    <table width="960px">
        <tr>
            @{
    int crow = 1;
    foreach (var item in Model)
    {
                <td style="border: 1px solid black;" width="600px">
                    <ul style="list-style: none;">
                        <li>
                            @Html.TextBox("txt")
                        </li>

                    </ul>
                </td>
        if (crow % 3 == 0)
        {                                                    
                <tr>
                    <td style="width: 285px; height: 50px">
                    </td>
                </tr>
        }
        crow++;
        }
     }
        </tr>
    </table>
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.