Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:13:44+00:00 2026-05-30T11:13:44+00:00

I created an editor template for enums which was working fine, until I decided

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:13:46+00:00Added an answer on May 30, 2026 at 11:13 am

    I can see at least 4 issues with your editor template:

    • You have an End If without an opening If so your editor template is likely to throw an exception
    • In order to determine the selected value you are comparing an enum value to a string: value.Equals(Model) whereas you should be comparing string with string: value.ToString().Equals(Model)
    • When rendering your dropdownlist you are using your Model value as name whereas you should be using an empty string in order to have correct name for this dropdownlist from the parent property.
    • Your editor template is now tied to the OsStatus enum as you are casting to it inside it. It would have been better to make this editor template a little more generic and reusable.

    Here’s the correct way:

    @ModelType String
    
    @code
        Dim options = [Enum].GetValues(ViewData("enumType")).Cast(Of Object)()
    
        Dim list As List(Of SelectListItem) =
                (From value In options
                Select New SelectListItem With { _
                    .Text = value.ToString(), _
                    .Value = value.ToString(), _
                    .Selected = value.ToString().Equals(Model) _
                }).ToList()
    End Code
    
    @Html.DropDownList("", list)
    

    And the correct way to invoke it is:

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

    or:

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

    Now when rendering this view make sure that the controller action actually passed a model and have the status string property set to some string value that is contained within the enum so that the correct option could be automatically pre-selected in the dropdown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an editor template for representing selecting from a dynamic dropdown list
I created a text editor in C# and I use a special file extension
I have created a Greasemonkey script that runs fine in the firebug editor, with
I have some data (which users input using WYSIWYG editor). I have created a
quick back story-- I am working on ASP.Net based template editor that lets authors
I have an enumeration in my project and I've created a custom editor template
I have created a custom editor template for DateTimeOffset: @model DateTimeOffset <div> @Html.LabelFor(m =>
I have created this editor template: @model DateTime? @using MyMvcApp.Properties <div id=dateTimePicker_@(ViewData.ModelMetadata.PropertyName)> <script type=text/javascript
I created an editor template for Boolean types, my problem it's when model attribute
I originally created an editor template like this @model MyModel var items = //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.