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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:08:18+00:00 2026-06-06T18:08:18+00:00

I am trying to create a strongly typed radiobuttonlist. I dont know how to

  • 0

I am trying to create a strongly typed radiobuttonlist. I dont know how to get the list of actions out of the ModelMetaData in the HtmlExtensionClass? The list of actions is passed in through MyViewmodel in the Index action.

helperclass c#

 public static class HtmlExtensions
    {

        public static MvcHtmlString RadioButtonForList<TModel, TProperty>(
           this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression
       )
        {
            var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            //var actions =  metaData.ModelType; //? how can i get my list of actions in here?

            var sb = new StringBuilder();

            foreach (var action in actions)
            {
                var id = string.Format(
                    "{0}_{1}_{2}",
                    htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix,
                    metaData.PropertyName,
                    action
                );

                var radio = htmlHelper.RadioButtonFor(expression, action, new { id = id }).ToHtmlString();
                sb.AppendFormat(
                    "<label for=\"{0}\">{1}</label> {2}",
                    id,
                    HttpUtility.HtmlEncode(action),
                    radio
                );
            }
            return MvcHtmlString.Create(sb.ToString());
        }
    }

controller index action

 public ActionResult Index()
        {
            List<PageAction> actionslist = new List<PageAction>();
            actionslist.Add(new PageAction() { action = "View" });
            actionslist.Add(new PageAction() { action = "Edit" });
            actionslist.Add(new PageAction() { action = "Create" });

            return View(new MyViewModel
            {
                actions = actionslist
            });
        }


  public class PageAction
    {
        public string user { get; set; }
        public string action { get; set; }
    }

    public class MyViewModel
    {
        public List<PageAction> actions { get; set; }
    }

view

@model radioButtonlist.Models.MyViewModel
@using radioButtonlist.Models;           

@using (Html.BeginForm())
{
    @Html.RadioButtonForList(x => x.actions)
}
  • 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-06T18:08:20+00:00Added an answer on June 6, 2026 at 6:08 pm

    The actions property is a list of PageAction. So you could force the helper to take as parameter a lambda expression which returns a list of this custom type, so that inside the helper you have access to the action and user properties:

    public static class HtmlExtensions
    {
        public static MvcHtmlString RadioButtonForList<TModel>(
            this HtmlHelper<TModel> htmlHelper, 
            Expression<Func<TModel, IEnumerable<PageAction>>> expression
        )
        {
            var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            var actions = metaData.Model as IEnumerable<PageAction>;
    
            var sb = new StringBuilder();
    
            foreach (var pageAction in actions)
            {
                var id = string.Format(
                    "{0}_{1}_{2}",
                    htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix,
                    metaData.PropertyName,
                    pageAction.action
                );
    
                var radio = htmlHelper.RadioButtonFor(expression, pageAction.action, new { id = id }).ToHtmlString();
                sb.AppendFormat(
                    "<label for=\"{0}\">{1}</label> {2}",
                    id,
                    HttpUtility.HtmlEncode(pageAction.action),
                    radio
                );
            }
            return MvcHtmlString.Create(sb.ToString());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get my strongly typed master page to work in my ASP
i'm trying to create a strongly-typed view using Visual Studio 2008. I can right-click
I'm trying to create an event delegate where the parameter is strongly typed to
I'm trying to create a strongly-typed Dictionary class in VB.NET. I'm tired of typing
I am trying to create url routing with strongly typed objects for pages but
I'm trying to create a strongly typed partial view <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master
I'm trying to create a strongly typed view model as John Sheehan suggests here
I'm trying to create a strongly typed model for one of my Views in
I am trying to create an email link using MVC3 and strongly typed modeling.
Trying to create a new Dedicated Cache Role in Windows Azure but get the

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.