1

我正在使用 MVC3 和 Razor 视图,我的视图填充了正确的数据

辅助模型

public partial class Visibility
    {
        public enum VisibilityLevel { ShowThis, HideThis, HideAll }
        ...
    }
public partial class Address
    {
        public Visibility.VisibilityLevel Visibility{
            get {
                ...

看法

    @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 />

控制器

 //
 // POST: /Address/Edit/5

 [HttpPost]
 public ActionResult Edit(Address addr,string submitButton)
 {
     ...

这会根据数据和模型定义正确填充页面,但是回发不会获得新值。当我检查控制器时,提交时传递的地址模型具有 RadioButton 的原始值,而不是用户选择或更改的值。我错过了什么?

4

1 回答 1

0

结果证明不是枚举的问题,我的自定义属性没有设置器。

改变了

辅助模型

    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;
        }
    }
}
于 2013-03-07T14:45:52.563 回答