Question

HI i am new to mvc and bootstrap.. i want to dynamically add two text box at run time in mvc4 and bootstrap.. i have tried many sites but i am not able to understand. please give me simple example

i have tried this

In model

 public class Gift
    {
        public string Name { get; set; }
        public double Price { get; set; }
    }

in controller

public ActionResult PanelEx()
        {

            var initialData = new[] {
        new Gift { Name = "Tall Hat", Price = 39.95 },
        new Gift { Name = "Long Cloak", Price = 120.00 },
    };
            return View(initialData);

        }

what should i wrote in model. how to do next step..i am stuck PLese help

Was it helpful?

Solution

public ActionResult PanelEx()
{
    var initialData = new List<Gift>{
    new Gift { Name = "Tall Hat", Price = 39.95 },
    new Gift { Name = "Long Cloak", Price = 120.00 },
};
    return View(initialData);
}

@model IEnumerable<Gift>

<div>
    @foreach(var item in Model)
    {
        <div>
        @Html.TextBoxFor(item=>item.Name)
        </div>
    }
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top