Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is what I ended up needing to do:</p> <p>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:</p> <pre><code> @Html.Raw(ViewBag.TextBoxes) </code></pre> <p>I also renamed the class for from 'RadioButtonItem' to 'TableOrViewItem' for clarity. Here's the Controller method I addeed:</p> <pre><code> [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&lt;SqlColumn&gt;() .Where( column =&gt; column.ObjectId == CurrentID ) .OrderBy( o =&gt; o.ColumnId ) .ToList(); string htmlColumns = string.Empty; foreach ( EF_Utility.Models.SqlColumn item in rawColumns ) { htmlColumns += "&lt;input checked=\"checked\" id=\"RadioButtonViewModel_CheckBox" + item.ColumnId + "\" name=\"CheckBox_" + item.ColumnId + "\" type=\"checkbox\" value=\"" + item.Name + "\"&gt;" + item.Name + " &lt;br&gt;"; } if(! string.IsNullOrEmpty(htmlColumns)) { htmlColumns += "&lt;br /&gt;&lt;center&gt;&lt;input type=\"submit\" value=\"Generate\" name=\"btnGenerate\" id=\"btnGenerate\" /&gt;&lt;/center&gt;"; htmlColumns += "&lt;input type=\"hidden\" name=\"id\" value=\"" + CurrentObjectId + "\" /&gt;"; htmlColumns += "&lt;input type=\"hidden\" name=\"name\" value=\"" + ViewBag.Selected + "\" /&gt;"; } ViewBag.TextBoxes = htmlColumns; /*var ColumnItemList = columns .Select( c =&gt; new ColumnItem { Name = c.Name, Selected = true, ObjectId = c.ObjectId } ) .Where( tvi =&gt; 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&lt;SqlObject&gt;().ToArray(); var model = objects .Select( o =&gt; new TableOrViewItem { Name = o.Name, Selected = false, ObjectId = o.ObjectId } ) .OrderBy( rb =&gt; rb.Name ); return View( model ); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload