Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8341583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:31:37+00:00 2026-06-09T05:31:37+00:00

I want to build a dynamic form from the scratch, and i already created

  • 0

I want to build a dynamic form from the scratch, and i already created the following elements:

A xml file with all fields that i want to show:

<?xml version="1.0" encoding="utf-8" ?>
<Fields>
    <FieldList>
        <Field>
            <Type>checkbox</Type>
            <Name>gender</Name>
            <DefaultValue>false</DefaultValue>
            <CssClass>myclass</CssClass>
        </Field>
        <Field>
            <Type>textbox</Type>
            <Name>name</Name>
            <DefaultValue>fill name</DefaultValue>
            <CssClass>formtextbox</CssClass>
        </Field>
    </FieldList>
</Fields>

A view typed to a class that i used to deserialize the xml:

@model Fields
@{
    if(Model!=null)
    {
        using (Html.BeginForm())
        {
            foreach (Field field in Model.FieldList)
            {
                switch(field.Type)
                {
                    case "textbox":
                        @Html.TextBox(field.Name, field.DefaultValue);
                    break;

                    case "checkbox":
                        @Html.CheckBox(field.Name,Convert.ToBoolean(field.DefaultValue));
                    break;
                }
            }    
        }
    }
}

By the moment the app is working properly but i have the following doubts:

1) I think is not an elegant solution since i have to put too many code in the view right?

2) I would like to add now some server validation. I normally work with data annotations, but here is not possible i guess since i dont know how is the thing that im submitting. Is there any way to create on the fly an class instance and add data anotations on the fly?

3) I created another action and controller that will handle the post. Since i dont know what im submitting my action doesnt receive as parameter nothing. I guess i have to use Request.Form from my action right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:31:38+00:00Added an answer on June 9, 2026 at 5:31 am

    My first thought was to implement a custom HtmlHelper method that will take the XML and generate the view for you. Like that you would only have one line of code in your view.
    As for validation, you can extend DataAnnotationsModelValidatorProvider and override GetValidators() to inject default mvc validators and/or your own validators based on whatever parameters or policies you see fit. These would be propagated to the client side as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build a python program that deletes all the photos from my
I want to build a dynamic navigation menu that will fill in automatically based
I want to build a Web page (in Asp.Net) containing a Dynamic Menu where
I want build a sketch pad app on iPhone, I assume that this type
I want to build flash application that can detect the user eyes color and
I want to build a form_tag that will allow me to post a new
I want to build a hierarchy from a one-dimensional array and can (almost) do
I want to build a dynamic ListView (like a chat list with different layouts/bubbles).
I am building a dynamic form system that will automatically assemble an HTML form
In a webproject i have a complex form to build a dynamic query. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.