[英]Razor view capture RadioButtonFor with enum source
I am using MVC3 and Razor view, I have the view populating with the proper data 我正在使用MVC3和Razor视图,该视图填充了正确的数据
HelperModel 辅助模型
public partial class Visibility
{
public enum VisibilityLevel { ShowThis, HideThis, HideAll }
...
}
public partial class Address
{
public Visibility.VisibilityLevel Visibility{
get {
...
View 视图
@Html.RadioButtonFor(m => m.HIDE_DATA, Models.Visibility.VisibilityLevel.ShowThis ) <span>Show @Model.TYPE_DESC address</span><br />
@Html.RadioButtonFor(m => m.HIDE_DATA, Models.Visibility.VisibilityLevel.HideThis) <span>Don't show @Model.TYPE_DESC address </span><br />
@Html.RadioButtonFor(m => m.HIDE_DATA, Models.Visibility.VisibilityLevel.HideAll) <span>Don't show ANY addresses</span><br />
Controller 控制者
//
// POST: /Address/Edit/5
[HttpPost]
public ActionResult Edit(Address addr,string submitButton)
{
...
This populated the page properly based on the data and model definition however the post back does not get the new value. 这会根据数据和模型定义正确填充页面,但是回发不会获得新值。 When I inspect the controller the Address model that is passed on submit has the original value of the RadioButton, not the value selected or changed by the user.
当我检查控制器时,提交时传递的地址模型具有RadioButton的原始值,而不是用户选择或更改的值。 What am I missing?
我想念什么?
Turned out to not be an issue with enum, my custom attribute did not have a setter. 事实证明这不是枚举的问题,我的自定义属性没有设置器。
Changed 已变更
HelperModel 辅助模型
Visibility.VisibilityLevel _vizibility;
public Visibility.VisibilityLevel Visibility{
get {
if (_vizibility != Models.Visibility.VisibilityLevel.ShowThis) //the default
return _hide_data;
var ans = new MacDirectEntities()
...
return ans.Visibility;
}
set {
_vizibility= value;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.