Monday 15 July 2013

c# - MVC: Dynamic forms, based on XML -



c# - MVC: Dynamic forms, based on XML -

i'm struggling bit dynamic form i'm trying create in asp.net mvc.

i have xml defines form this:

<?xml version="1.0" encoding="utf-16"?> <contenttype xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <fields> <contentfield> <name>url</name> <value>home</value> </contentfield> <contentfield> <name>value</name> <value>sample value</value> </contentfield> </fields> </contenttype>

now, i've managed create form in mvc using next syntax:

@using (html.beginform("edit", "content", formmethod.post)) { @html.labelfor(model => model.name) @html.textboxfor(model => model.name) <br /> foreach (var field in model.fields) { @html.label(field.name, field.name) @html.textbox(field.name, field.value) <br /><br /> } <input type="submit" name="save" value="save" /> }

so, generate required fields, problem arises in post of controller, how assign values of dynamic generated fields right properties of model?

kind regards,

if utilize index access info in model

for (int = 1; <= model.fields.length; i++) { @html.lablefor(model => model.fields[i].value, model.fields[i].name) @html.textboxfor(model => model.fields[i].value) <br /><br /> }

you should able create method marked post using same model.

c# asp.net xml asp.net-mvc asp.net-mvc-4

No comments:

Post a Comment