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 7183311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:57:13+00:00 2026-05-28T17:57:13+00:00

I am trying to render a ViewModel using Razor and MVC3. For some reason

  • 0

I am trying to render a ViewModel using Razor and MVC3. For some reason my SelectList (WidgetTypes below) does not render even though the rest all render just fine. Can anyone shed some light as to why not? I do not want to change the View to use @Html.EditorFor(m => m.SystemName) etc. for each field because I use dynamic models for the widgets which will cause the same problem.

My ViewModel:

public class CreateWidgetViewModel 
{
    [Required]
    public string Title { get; set; }

    [Required(ErrorMessage = "The System Name is required")]
    [Display(Name = "System Name")]
    public string SystemName { get; set; }

    [Required]
    [Display(Name = "Widget Type")]
    public string WidgetType { get; set; }

    [Required]
    [Display(Name = "Widget Types")]
    public SelectList WidgetTypes { get; set; }
}

My Controller:

[HttpGet]
public ActionResult Create()
{
    var widgetTypes = from wt in _widgetService.WidgetTypes
                      select new
                      {
                          Name = wt.WidgetName,
                          WidgetType = wt.GetType().AssemblyQualifiedName
                      };

    var viewModel = new CreateWidgetViewModel
    {
        WidgetTypes = new SelectList(widgetTypes, "WidgetType", "Name")
    };

    if (Request.IsAjaxRequest())
    {
        return PartialView(viewModel);
    }
    return View(viewModel);
}

My View:

@{
    ViewBag.CurrentPage = "widgets";
}
<h2>@ViewBag.Title</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div>
            @Html.EditorFor(model => model)
        </div>
    </fieldset>
    <div>
        <input type="submit" value="Save" />&nbsp;or&nbsp;@Ajax.ActionLink("Back to list", "Index", "Widget", 
        new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "ajax-replace" })
    </div>
}
  • 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-28T17:57:15+00:00Added an answer on May 28, 2026 at 5:57 pm

    You need to use the Html.DropdownListFor helper if you want to generate a drop down list. The fact that you have used SelectList as type to some of your properties doesn’t mean that the default editor template will render a <select> box. So you will have to write a custom editor template.

    You may take a look at the following blog post to see how those default templates are implemented.

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

Sidebar

Related Questions

I am trying to build a sample for myself using MVC3, Razor view engine
I'm trying to render a textured quad in d3d, and its not using the
I am trying to render a model in Direct3D using DrawIndexedPrimitives . However, I
I'm trying to render a bit of text using Core Graphics APIs and I'm
I am trying to render a complex XML document as webpage(FF only) using a
I am trying to render video via the NDK, to add some features that
I'm trying to render some response like this def doAjax = Action { request
I'm trying to render images with verdana text using PHP imagettftext function. However, all
Trying to get my ducks in a row with MVC3 + Razor! I finally
I am trying to render a float value using NSNumberFormatter's SpellOutStyle, but the results

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.