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

  • Home
  • SEARCH
  • 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 3349570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:40:51+00:00 2026-05-18T01:40:51+00:00

I can bind to properties in the ViewModel fairly simply like so: <%=Html.RadioButtonFor(m =>

  • 0

I can bind to properties in the ViewModel fairly simply like so:

<%=Html.RadioButtonFor(m => m.isCool, true%>cool<br/>
<%=Html.RadioButtonFor(m => m.isCool, false)%>not cool<br/>

but what if I wanted to bind to collection items within the ViewModel. I’m not sure if it’s possible. Here’s what I have:

My ViewModel:

namespace MvcApplication3.ViewModels
{
    public class cpApprovalViewModel
    {
        // My internal class
        public class PersonImage
        {
            public bool isApproved { get; set; }
            public bool isProFilePic { get; set; }
            public string uriId { get; set; }
            public string urlPath { get; set; }
        }

        public string displayName { get; set; }
        public bool isCool { get; set; }
        public List<PersonImage> personImages { get; set; }
    }
}

My Controller:

public class cpApprovalController : Controller
    {
        //
        // GET: /cpApproval/

        public ActionResult Index()
        {
            cpApprovalViewModel viewModel = new cpApprovalViewModel();
            viewModel.displayName = "jon doe";
            viewModel.personImages = new List<cpApprovalViewModel.PersonImage>()
            {
                new cpApprovalViewModel.PersonImage(){isApproved = false, uriId = "1", isProFilePic = false, urlPath="someImagePath1.jpg" },
                new cpApprovalViewModel.PersonImage(){isApproved = false, uriId = "2", isProFilePic = false, urlPath="someImagePath2.jpg" },
                new cpApprovalViewModel.PersonImage(){isApproved = false, uriId = "3", isProFilePic = false, urlPath="someImagePath2.jpg" }
            };

            return View(viewModel);
        }

        //cpApprovalViewModel viewModel
        [HttpPost]
        public void formReceiver(cpApprovalViewModel viewModel)
        {
            // This is where I'd like to get access to the changed personImages (approved/disapproved )
        }
    }

My View:

<%: Model.displayName %><br /><br />
<% using (Html.BeginForm("formReceiver", "cpApproval", FormMethod.Post )){ %>

    <% foreach (var anImage in Model.personImages){ %>
        <%: Html.RadioButtonFor(model => model.personImages.Single(i => i.uriId == anImage.uriId), true, new { id = anImage.uriId })%> Approve <br />
        <%: Html.RadioButtonFor(model => model.personImages.Single(i => i.uriId == anImage.uriId), false, new { id = anImage.uriId })%> Deny <br />
        <hr />
    <% } %>

    <input type="submit" value="Save" />
<%} %>

I’m getting the following error:
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

Am I trying to do something impossible here? I hope this makes sense. 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-18T01:40:51+00:00Added an answer on May 18, 2026 at 1:40 am

    Yes – what you’re trying to do is possible.

    I think your problem is that you’re trying to get the relevant image again using .Single, when you already have the item in the foreach loop.

    Try changing:

    <%: Html.RadioButtonFor(model => model.personImages.Single(i => i.uriId == anImage.uriId), true, new { id = anImage.uriId })%> Approve <br />
    

    To:

    <%: Html.RadioButtonFor(model => anImage, true, new { id = anImage.uriId })%> Approve <br />
    

    More info on model-binding to a Collection here.

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

Sidebar

Related Questions

In lisp I can bind free variables bound in a closure like this... (let
I have a user control where the XAML of the control can bind to
How can I bind arguments to a Python function so that I can call
With ASP.NET 3.5 I can easily bind to an XML file by using an
I'm building an application in C# using WPF. How can I bind to some
i'm trying to create a ObjectDataSource which I can use to bind to a
I know that in C#, properties are supposed to be quick operations (not reading
I just read about KnockoutJS and when I try to bind to sub-properties on
How can bind onload event on body element of second tab in Firefox extension?
I know that we can bind the data to each control within ItemTemplate as

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.