Answered by:
How to do multiple radio button list using Enum in MVC3 and Return to View

Question
-
User-129908252 posted
I created in model class with property name enum type and create for a list of items and how to access in that to controller to view.
Thanks in Advance
Monday, July 28, 2014 11:05 AM
Answers
-
User831885415 posted
Enum
namespace Models { public enum numbers { one = 1, two = 2, three = 3 } }
View
@{var numList = Enum.GetValues(typeof(Models.numbers));} @foreach (object radiotext in numList) { @Html.RadioButton("radioname", radiotext.ToString())@radiotext.ToString() }
All the best
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 29, 2014 12:33 AM -
User1176121428 posted
Hi jagan12013,
Thanks for your post.
cnuonline's approach is good, you can refer to it. Here is a complete sample according to cnuonline's approach
model:
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace appradiobutton.Models { public class mymodel { public enum numbers { one = 1, two = 2, three = 3 } } }
controller:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace appradiobutton.Controllers { public class HomeController : Controller { public ActionResult demo() { return View(); } } }
view:
@model IEnumerable<appradiobutton.Models.mymodel> @{ ViewBag.Title = "demo"; var numList = Enum.GetValues(typeof(appradiobutton.Models.mymodel.numbers)); } @foreach (var radiotext in numList) { @Html.RadioButton("radioA", radiotext.ToString()) @radiotext.ToString() }
Hope this helps u.
Best Regards,
Eileen
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 29, 2014 2:56 AM
All replies
-
User831885415 posted
Enum
namespace Models { public enum numbers { one = 1, two = 2, three = 3 } }
View
@{var numList = Enum.GetValues(typeof(Models.numbers));} @foreach (object radiotext in numList) { @Html.RadioButton("radioname", radiotext.ToString())@radiotext.ToString() }
All the best
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 29, 2014 12:33 AM -
User1176121428 posted
Hi jagan12013,
Thanks for your post.
cnuonline's approach is good, you can refer to it. Here is a complete sample according to cnuonline's approach
model:
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace appradiobutton.Models { public class mymodel { public enum numbers { one = 1, two = 2, three = 3 } } }
controller:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace appradiobutton.Controllers { public class HomeController : Controller { public ActionResult demo() { return View(); } } }
view:
@model IEnumerable<appradiobutton.Models.mymodel> @{ ViewBag.Title = "demo"; var numList = Enum.GetValues(typeof(appradiobutton.Models.mymodel.numbers)); } @foreach (var radiotext in numList) { @Html.RadioButton("radioA", radiotext.ToString()) @radiotext.ToString() }
Hope this helps u.
Best Regards,
Eileen
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 29, 2014 2:56 AM -
User-2012801151 posted
use this code: <div class="next-row"> @Html.RadioButtonFor(m => m.TransactionType, "14", new { @type = "radio", @class = "styled", @name = "optionsRadios2", @id = "option13" }) Third Party Fund Transfers @Html.ValidationMessageFor(m => m.TransactionType, "", new { @style = "color: Red;" }) </div> <div class="next-row"> @Html.RadioButtonFor(model => model.TransactionType, "12", new { @type = "radio", @class = "styled", @name = "optionsRadios2", @id = "option16" }) Overseas Fund Transfers @Html.ValidationMessageFor(m => m.TransactionType,"", new { @style = "color: Red;"}) </div>
Tuesday, July 29, 2014 4:43 AM