Question

I created an editor template for enums which was working fine, until I decided to use Ajax.BeginForm. The property status has the following definition:

<DisplayName("Status")>
<UIHint("enum")>
Public Property status As String

I already tried the following approachs:

@Using Ajax.BeginForm("New", "Os", Nothing)
    @Html.EditorFor(Function(m) m.status, "Enum", New With { .enumType = GetType(OsStatus)})
End Using

@Ajax.BeginForm("New", "Os", Nothing)

@Html.EditorFor(Function(m) m.status, "Enum", New With { .enumType = GetType(OsStatus)})

@Using Html.BeginForm()
    @Html.EditorFor(Function(m) m.status, "Enum", New With { .enumType = GetType(OsStatus)})
End Using

@Html.BeginForm()
@Html.EditorFor(Function(m) m.status, "Enum", New With { .enumType = GetType(OsStatus)})

None of the above worked.

The code for my template is as follows

@ModelType String

@code

    Dim options As IEnumerable(Of OsStatus)
    options = [Enum].GetValues(ViewData("enumType")).Cast(Of OsStatus)()


    Dim list As List(Of SelectListItem) = 
            (from value in options 
            select new SelectListItem With { _
                .Text = value.ToString(), _
                .Value = value.ToString(), _
                .Selected = value.Equals(Model) _
            }).ToList()
    End If
End Code

@Html.DropDownList(Model, list)

After calling a .BeginForm method, my template is still called, but the Model property inside my template is null.

ANY ideas?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top