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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:45:03+00:00 2026-05-13T12:45:03+00:00

Controller public ActionResult Create() { return View(new PageViewModel()); } [HttpPost] public ActionResult Create(Page page)

  • 0

Controller

public ActionResult Create()
{
   return View(new PageViewModel());
} 

[HttpPost]
public ActionResult Create(Page page)
{
   try
   {
      repPage.Add(page);
      repPage.Save();

      return RedirectToAction("Edit");
   }
   catch
   {
      return View(new PageViewModel());
   }
}

PageViewModel

public class PageViewModel
{
    public Page Page { get; set; }
    public List<Template> Templates { get; set; }

    private TemplateRepository repTemplates = new TemplateRepository();

    public PageViewModel()
    {
        Page = new Page();
        Templates = repTemplates.GetAllTemplates().ToList(); 
    }
}

Parts of my View

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Website.Models.PageViewModel>" %>

<%= Html.TextBoxFor(model => model.Page.Name, new { @style = "width:300px;" })%>

<%= Html.DropDownListFor(model => model.Page.Template, new SelectList(Model.Templates, "ID", "Name"), new { @style = "width:306px;" })%>

Template:
ID
Name
Page:
ID
Name
TemplateID

My dropdownlist is populated correctly in the view, no problems there. My problem is that I dont get the selected value from the dropdownlist.

In my controller I i put a breakpoint in Edit and see that the Name textbox is populated with the value I type into it. But the selected from the dropdownlist is set to null.

alt text http://www.mgmweb.no/images/debug.jpg

Am I missing something, I thought it should set the correct Template value into the Page object. What am I doing wrong?

  • 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-13T12:45:04+00:00Added an answer on May 13, 2026 at 12:45 pm

    The only thing that you get back from the web page is the id of the selected template. The default model binder doesn’t know how to take this id and retrieve the correct template object from your repository. To do this you would need to implement a custom model binder that is able to retrieve the values from the database, construct a Template object, and assign it to the Page. Or… you could do this manually in the action given that, according to your comments elsewhere, you know how to get the template’s id from the posted values.

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

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The most practical way is to determine what invariants must… May 16, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer I think this approach is acceptable single threaded, but if… May 16, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer Arguments with default values must follow arguments without default values.… May 16, 2026 at 4:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following controller: class FooController : Controller { public ActionResult SomeAction(id) {
I'm trying to create a view that contains a list of checkboxes that is
I have a website where I allow users to create new Part records. I'm
I want to have two separate forms on a single create page and one
Should be an easy question to answer. I am trying to create an object
I am starting out on a new project (well, restarting an existing one), and
Does this <% Html.EnableClientValidation(); %> really enable client validation that validation without page refresh
is there any possibility to create a maproute which would use always one method
I like using Models for validation <!-- ViewPage --> <%@ Page Language=C# Inherits=ViewPage<TopicModel> %>
I am having the error message:I can`t figure out what is wrong. Can someone

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.