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 8644989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:26:02+00:00 2026-06-12T12:26:02+00:00

I have a Model defined that gets me a View with a list of

  • 0

I have a Model defined that gets me a View with a list of RadioButtons, per IEnumerable.

Within that Model, I want to display a list of checkboxes that will vary based on the item selected. Finally, there will be a Textarea in the same view once the user has selected from the available checkboxes, with some dynamic text there based on the CheckBoxes that are selected. What we should end up with is a Table-per-hierarchy.

The layout is such that the RadioButtonList is in the first table cell, the CheckBoxList is in the middle table cell, and the Textarea is ini the right table cell.

If anyone can guide me to what my model-view should be to achieve this result, I’ll be most pleased…

Here are my codes:

//
// View Model for implementing radio button list

public class RadioButtonViewModel
{
    // objects
    public List<RadioButtonItem> RadioButtonList { get; set; }
    public string SelectedRadioButton { get; set; }
}

//
// Object for handling each radio button

public class RadioButtonItem
{
    // this object
    public string Name { get; set; }
    public bool Selected { get; set; }
    public int ObjectId { get; set; }
    // columns
    public virtual IEnumerable<CheckBoxItem> CheckBoxItems { get; set; }
}

//
// Object for handling each checkbox

public class CheckBoxViewModel
{
    public List<CheckBoxItem> CheckBoxList { get; set; }
}

//
// Object for handling each check box

public class CheckBoxItem
{
    public string Name { get; set; }
    public bool Selected { get; set; }
    public int ObjectId { get; set; }
    public virtual RadioButtonItem RadioButtonItem { get; set; }
}

and the view

@model IEnumerable<EF_Utility.Models.RadioButtonItem>

@{
    ViewBag.Title = "Connect";
    ViewBag.Selected = Request["name"] != null ? Request["name"].ToString() : "";
}

@using (Html.BeginForm("Objects" , "Home", FormMethod.Post) ){

@Html.ValidationSummary(true)

<table>
    <tbody>
        <tr>
            <td style="border: 1px solid grey; vertical-align:top;">

                <table>
                    <tbody>
                        <tr>
                            <th style="text-align:left; width: 50px;">Select</th>
                            <th style="text-align:left;">View or Table Name</th>
                        </tr>
                        @{
                        foreach (EF_Utility.Models.RadioButtonItem item in @Model )
                        {
                        <tr>
                            <td>
                                @Html.RadioButton("RadioButtonViewModel.SelectedRadioButton", 
                                    item.Name, 
                                    ViewBag.Selected == item.Name ? true : item.Selected, 
                                    new { @onclick = "this.form.action='/Home/Connect?name=" + item.Name + "'; this.form.submit(); " })
                            </td>
                            <td>
                                @Html.DisplayFor(i => item.Name)
                            </td>
                        </tr>
                        }
                        }
                    </tbody>
                </table>

            </td>
            <td style="border: 1px solid grey; width: 220px; vertical-align:top; @(ViewBag.Selected == "" ? "display:none;" : "")">

                <table>
                    <tbody>
                        <tr>
                            <th>Column
                            </th>
                        </tr>
                        <tr>
                            <td><!-- checkboxes will go here -->
                            </td>
                        </tr>
                    </tbody>
                </table>

            </td>
            <td style="border: 1px solid grey; vertical-align:top; @(ViewBag.Selected == "" ? "display:none;" : "")">
                <textarea name="output" id="output" rows="24" cols="48"></textarea>
            </td>
        </tr>
    </tbody>
</table>
}

and the relevant controller

public ActionResult Connect() 
    {
        /* TEST SESSION FIRST*/ 
        if(  Session["connstr"] == null)
            return RedirectToAction("Index");
        else
        {
            ViewBag.Message = "";
            ViewBag.ConnectionString = Server.UrlDecode( Session["connstr"].ToString() );
            ViewBag.Server = ParseConnectionString( ViewBag.ConnectionString, "Data Source" );
            ViewBag.Database = ParseConnectionString( ViewBag.ConnectionString, "Initial Catalog" );

            using( var db = new SysDbContext(ViewBag.ConnectionString))
            {
                var objects = db.Set<SqlObject>().ToArray();

                var model = objects
                    .Select( o => new RadioButtonItem { Name = o.Name, Selected = false, ObjectId = o.Object_Id, CheckBoxItems = Enumerable.Empty<EF_Utility.Models.CheckBoxItem>() } )
                    .OrderBy( rb => rb.Name );

                return View( model );
            }
        }
    }

What I am missing it seems, is the code in my Connect() method that will bring the data context forward; at that point, it should be fairly straight-forward to set up the Html for the View.

EDIT
** So I am going to need to bind the RadioButtonItem to the view with something like the following, except my CheckBoxList will NOT be an empty set.

    //
    // POST: /Home/Connect/

    [HttpPost]
    public ActionResult Connect( RadioButtonItem rbl )
    {
        /* TEST SESSION FIRST*/
        if ( Session["connstr"] == null )
            return RedirectToAction( "Index" );
        else
        {
            ViewBag.Message = "";
            ViewBag.ConnectionString = Server.UrlDecode( Session["connstr"].ToString() );
            ViewBag.Server = ParseConnectionString( ViewBag.ConnectionString, "Data Source" );
            ViewBag.Database = ParseConnectionString( ViewBag.ConnectionString, "Initial Catalog" );

            using ( var db = new SysDbContext( ViewBag.ConnectionString ) )
            {
                var objects = db.Set<SqlObject>().ToArray();

                var model = objects
                    .Select( o => new RadioButtonItem { Name = o.Name, Selected = false, ObjectId = o.Object_Id, CheckBoxItems = Enumerable.Empty<EF_Utility.Models.CheckBoxItem>() } )
                    .OrderBy( rb => rb.Name );

                return View( model );
            }
        }
    }
  • 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-12T12:26:03+00:00Added an answer on June 12, 2026 at 12:26 pm

    Here is what I ended up needing to do:

    Define a new Controller Method to handle the post back with the relevant Model class, and process the nested related Checkboxes with this in the View:

        @Html.Raw(ViewBag.TextBoxes)
    

    I also renamed the class for from ‘RadioButtonItem’ to ‘TableOrViewItem’ for clarity.
    Here’s the Controller method I addeed:

        [HttpPost]
        public ActionResult Connect( TableOrViewItem rbl )
        {
            /* TEST SESSION FIRST*/
            if ( Session["connstr"] == null )
                return RedirectToAction( "Index" );
            else
            {
                ViewBag.Message = "";
                ViewBag.ConnectionString = Server.UrlDecode( Session["connstr"].ToString() );
                ViewBag.Server = ParseConnectionString( ViewBag.ConnectionString, "Data Source" );
                ViewBag.Database = ParseConnectionString( ViewBag.ConnectionString, "Initial Catalog" );
                ViewBag.Selected = Request["name"] != null ? Request["name"].ToString() : "";
                ViewBag.ObjectID = Request["id"] != null ? Request["id"].ToString() : "";
    
                using ( var dbo = new SqlObjectContext( ViewBag.ConnectionString ) )
                {
    
                    // obtain this item's objectid
                    string CurrentObjectId = Request["id"].ToString();
                    int CurrentID = StringToInt( CurrentObjectId );
    
                    // populate Checkbox Area
    
                    var rawColumns = dbo.Set<SqlColumn>()
                        .Where( column => column.ObjectId == CurrentID )
                        .OrderBy( o => o.ColumnId )
                        .ToList();
    
                    string htmlColumns = string.Empty;
    
                    foreach ( EF_Utility.Models.SqlColumn item in rawColumns )
                    {
                        htmlColumns += "<input checked=\"checked\" id=\"RadioButtonViewModel_CheckBox" 
                            + item.ColumnId + "\" name=\"CheckBox_" + item.ColumnId 
                            + "\" type=\"checkbox\" value=\"" + item.Name + "\">" 
                            + item.Name + " <br>";
                    }
                    if(! string.IsNullOrEmpty(htmlColumns))
                    {
                        htmlColumns += "<br /><center><input type=\"submit\" value=\"Generate\" name=\"btnGenerate\" id=\"btnGenerate\" /></center>";
                        htmlColumns += "<input type=\"hidden\" name=\"id\" value=\"" + CurrentObjectId + "\" />";
                        htmlColumns += "<input type=\"hidden\" name=\"name\" value=\"" + ViewBag.Selected + "\" />";
                    }
    
                    ViewBag.TextBoxes = htmlColumns;
    
                    /*var ColumnItemList = columns
                        .Select( c => new ColumnItem { Name = c.Name, Selected = true, ObjectId = c.ObjectId } )
                        .Where( tvi => tvi.ObjectId == CurrentID );
                    */
    
                    // Check to see if the user wants the list generated
    
                    if(Request["btnGenerate"] != null)
                    {
                        string sNewLine = System.Environment.NewLine;
                        string htmlText = "[Table( \"" + ViewBag.Selected +"\" )]" + sNewLine +
                            "public class " + POCOFormated( ViewBag.Selected ) + sNewLine + "{";
                        string tempColumn = string.Empty;
                        string tempName = string.Empty;
    
                        foreach(string key in Request.Form)
                        {
                            if(!key.StartsWith("CheckBox_")) continue;
    
                            tempName = POCOFormated( Request.Form[key] );
                            htmlText = htmlText +
                                sNewLine + "\t" +
                                "public " + "...fieldtype..." + " " + tempName.Trim() + " { get; set; }" +
                                sNewLine; 
                        }                       
                        htmlText = htmlText + sNewLine + "}";
    
                        ViewBag.TextArea = htmlText;
                    }
    
                    var objects = dbo.Set<SqlObject>().ToArray();
    
                    var model = objects
                        .Select( o => new TableOrViewItem { Name = o.Name, Selected = false, ObjectId = o.ObjectId } )
                        .OrderBy( rb => rb.Name );
    
    
                    return View( model );
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base model that I extend from. In it, I have defined
I have defined a function in my Navigation model that executes a query, and
I have a Rails engine that defines a class method top(count) on a model
I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
Let's say i have a Model defined as: Foo {Id, Date} . Is there
All, i have the following model defined, class header(models.Model): title = models.CharField(max_length = 255)
Say I have a model object 'Person' defined, which has a field called 'Name'.
Lets say I have model inheritance set up in the way defined below. class
So I have a self-joining model defined. Basically a post on a forum, and

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.