I am trying to generate such HTML
<form action="/some/process" method="post">
<input type="hidden" name="foo.a" value="aaa"/>
<input type="hidden" name="bar.b" value="bbb"/>
<input type="submit" />
</form>
so it can be processed by this Action:
public ActionResult Process(Foo foo, Bar bar)
{
...
}
Given the Action code
public ActionResult Edit()
{
ViewData["foo"] = new Foo { A = "aaa" };
ViewData["bar"] = new Bar { B = "bbb" };
return View();
}
what should I write in Edit.aspx view? I don’t want to write names ‘foo.a’ and ‘bar.b’ manually.
String-indexed
ViewDatais bad. What you probably want to do is make a little wrapper class for your multi-variable view data and pass that to a strongly typed view. IE:Then your view is just strongly typed to
FooBarViewDataand you can call members of that object using theModelproperty.