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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:25:34+00:00 2026-05-17T19:25:34+00:00

I’m currently in the process of creating a shared Edit/Create view for my game

  • 0

I’m currently in the process of creating a shared Edit/Create view for my game review project and have hit a snag. Each game can be a title on a variety of platforms. I have this mapped as a many-to-many relationship in my EF4 model. For my view, I’d like to have a series of checkboxes with the names of each platform, and, for the Edit view, have the correct boxes checked.

I can create the checkboxes easily with an HTML helper. My biggest problem is figuring out how to tell the helper to turn on isChecked on the correct platform values. Here’s what I have so far:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<HandiGamer.ViewModels.AdminGameReviewViewModel>" %>

<p>
    <%: Html.LabelFor(model => model.GameData.GameTitle) %>
    <%: Html.TextBoxFor(model => model.GameData.GameTitle) %>
    <%: Html.ValidationMessageFor(model => model.GameData.GameTitle) %>
</p>
<p>
    <%: Html.LabelFor(model => model.Genres) %>
    <%: Html.DropDownList("Genre", new SelectList(ViewData["Genres"] as IEnumerable, "GenreID", "Name", Model.GameData.GenreID) %>
</p>
<p>
    <%: Html.LabelFor(model => model.Platforms) %>
    <% foreach(var item in Model.Platforms) { %>
        <%: Html.CheckBox(item.Name) %>
    <% } %>
</p>

And, my view model is:

public class AdminGameReviewViewModel
{
    public Game GameData { get; set; }
    public List<Genre> Genres { get; set; }
    public List<Platform> Platforms { get; set; }
}

Populated by:

    public ActionResult EditReview(int id)
    {
        var game = _siteDB.Games.Include("Genre").Include("Platforms").Include("Content").Single(g => g.GameID == id);
        var genres = _siteDB.Genres.ToList();
        var platforms = _siteDB.Platforms.ToList();
        var model = new { GameData = game, Genres = genres, Platforms = platforms }; 

        return View(model);
    }

So, I really just need a nudge in the right direction with the logic to determine which boxes should be checked.

Thanks.

  • 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-05-17T19:25:35+00:00Added an answer on May 17, 2026 at 7:25 pm

    Try using Html.CheckBoxFor

    The predicate is an expression bound to the field (which should be a boolean).

    <%: Html.CheckBoxFor(item => item.Name) %>
    

    Also, i noticed in your Controller you are returning an anonymous type – that should be strongly-typed to your AdminGameReviewViewModel view-model, otherwise the model binding will not work.

    e.g:

    var model = new AdminGameReviewViewModel { GameData = game, Genres = genres, Platforms = platforms }; 
    

    I’m not really sure what model property you want you want for the checkbox. Are you sure an item can/can’t have a Name? It sounds like item.Name is a string, which is not valid for a checkbox – you should be binding to a boolean flag.

    Maybe you should add another property to your ViewModel?

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.