tags:

views:

20

answers:

1

I am looking for solutions / suggestions on posting an string[]. My Model (Program), defines the target property (Levels) as a string. I can achieve this by just using FormCollection, but would prefer to pass that string[] right into the model from the post. Here are snippets:

ProgramConotroller/Create

//
// POST: /Program/Create
[HttpPost]
public ActionResult Create(Program obj)
{
    if(_service.CreateProgram(obj))
    {
        return RedirectToAction("Index");
    }
    // Add data to view data, remove if not necessary
    AddToViewData(obj);
    return View("Create", obj);
}

View/Create

...
<p>
<label>Program Levels</label>
<%= Html.ValidationMessageFor(model => model.Levels) %> <br />
<% foreach (Level level in (IEnumerable)ViewData["ProgramLevels"]) { %>
<input type="checkbox" name="Levels" value="<%= level.Id %>" <%= CommonExtensions.isChecked(level.Id.ToString(), Model.Levels) %> /><%= level.Name %><br />
<% } %>
</p>
...
+2  A: 

Read about Model Binding to Arrays.

Yuriy Faktorovich
I should have know to check Scott's blog before posting... silly silly me.
gnome