I have a table in the database that is a list of Products. Then I have a Fundraiser class (made into a controller and views) that will have a "collection" of Products. The point is that "for this fundraiser, I am selling these selected products".
My idea is to have a list of checkboxes so that the user can select which products are to be included in the fundraiser. I know that the typical way of doing this is to have an intermediary table that has a compound key of ProductID and FundraiserID. I don't want to do this.
Instead my idea is to make the list of products as checkboxes, use JavaScript to create a JSON string as the user selects/deselects the checkboxes, then save that JSON string into a simple text field in the Fundraiser table.
public class Fundraiser
{
public int FundraiserID { get; set; }
public string EventName { get; set; }
public string ItemsList { get; set; }
}
public class Product
{
public int ProductID { get; set; }
public string Name { get; set; }
}
So, there are two ways that I'm thinking this can go.
How do I write raw HTML so that I can manually iterate through the resultset of the Products table and create the checkboxes. Right now, the HTML I write is shown literally on the page instead of interpreted.
ViewData["ProductList"] = "<input type='checkbox' id='prod12' checked>"; // Is escaped or something so that it does not render as an HTML input
OR
Is there an HTML helper or some other tool that will do this through class methods or something (so that I can do it in the 'proper' OOP style)?
ViewData["ProductList"] = new ListOfCheckBoxes(_context.Products, "ProductID"......
I have a background in PHP programming, and I rarely used third-party code, so having all these high-level "helpers" is really confusing for me. I just want to write the code!