mvc html.radiobutton,asp.net mvc - pass enum to html.radiobuttonfor MVC3 - Stack Overflow

I Have an Enum Called ActionStatus that has 2 possible values open=0 and closed = 1

public enum ActionStatus

{

Open,

Closed

}

I want to build radio button group in my edit and create views that uses the enum to populate the radio buttons with a) a default value in the create view and b) the currently selected option in the edit view.

Do i need an extension method for this, and has anybody already created one?

EDIT: After Darins's answer below this is my Model class

namespace Actioner.Models

{

[MetadataType(typeof(MeetingActionValidation))]

public class MeetingAction

{

[Key]

public int MeetingActionId { get; set; }

[Required]

[Display(Name = "Description")]

public string Description { get; set; }

[Required]

[Display(Name = "Review Date")]

public DateTime ReviewDate { get ;set; }

public int Status{ get; set; }

[ScaffoldColumn(false)]

public int MeetingId { get; set; }

//public virtual Meeting Meeting { get; set; }

//public virtual ICollection Users { get; set; }

public virtual ICollection ActionUpdates { get; set; }

public MeetingActionStatus ActionStatus { get; set; }

}

public enum MeetingActionStatus

{

Open,

Closed

}

and this is my view

@model Actioner.Models.MeetingAction

@using Actioner.Helpers

@Html.LabelFor(model => model.Description)

@Html.EditorFor(model => model.Description)

@Html.ValidationMessageFor(model => model.Description)

@Html.LabelFor(model => model.ReviewDate)

@Html.EditorFor(model => model.ReviewDate)

@Html.ValidationMessageFor(model => model.ReviewDate)

@Html.LabelFor(model => model.Status)

@Html.RadioButtonForEnum(x => x.ActionStatus)

And this is my create controller action

public virtual ActionResult Create(int id)

{

var meetingAction = new MeetingAction

{

MeetingId = id,

ReviewDate = DateTime.Now.AddDays(7)

};

ViewBag.Title = "Create Action";

return View(meetingAction);

}

The enum displays fine in the view, but the currently selected option is not persisted to the database

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值