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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:19:31+00:00 2026-06-14T23:19:31+00:00

I am a real beginner at ASP.NET and working with MVC2 + EF4 in

  • 0

I am a real beginner at ASP.NET and working with MVC2 + EF4 in Visual Studio 2010.

I am trying to use the MVVM pattern and strongly typing my View to a ViewModel.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"        AutoEventWireup="True" CodeBehind="~/Views/Options/Index.aspx.cs" Inherits="System.Web.Mvc.ViewPage<OptionsViewModel>" %>

My OptionsViewModel looks like this:

 public class OptionsViewModel
{
    public List<DeskPreference> DeskPreferences { get; set; }
    public List<DayPreference> DayPreferences { get; set; }
}

In the controller I create a new OptionsViewModel and do return View(myOptionsViewModel);

Then, for example, I want to check/uncheck some boxes based on what is in DayPreference. I don’t get how to access the model from my code behind file, which looks like this:

using System.Web.Mvc;
using DeskRota_v1.ViewModels;

public class OptionsPage : System.Web.Mvc.ViewPage<OptionsViewModel>
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        setCheckBoxes();
    }

    private void setCheckBoxes()
    {           
        foreach (DayPreference dayPreference in Model.DayPreferences)
        {
\\ check boxes here
}
}

It comes up with “The name ‘Model’ does not exist in the current context”. Also if I try to do <% Model. %> in the view there is no intellisense, which I thought there should be. Could somebody please explain what I am doing wrong? How am I supposed to access the ViewModel and its properties?

  • 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-06-14T23:19:33+00:00Added an answer on June 14, 2026 at 11:19 pm

    Your controller will have two overloads of each action method for each view that you need to post back: one with an HttpGet signature and one with an HttpPost signature. The GET version will be called on the first load of the page and will set the initial page values.

    The POST version will be called on form submit and accept your viewmodel as an arg. MVC will automagically reconstruct it with the values that were posted in your form (assuming you’re using relatively simple types. More complex types is doable but more complicated).

    My own convention is to have a work unit in the ViewModel that is responsible for persisting or otherwise processing the values that were submitted. Do NOT put this sort of thing in the controller.

    Your viewmodel will need a parameterless constructor, which is the version MVC will use when reconstituting it on page submit. In general I also have a second constructor I use on the GET version so that the VM can instantiate it’s initial values.

    [HttpGet]
    public ActionResult Index(int somethingICareAbout)
    {
      return View(new IndexViewModel(somethingICareAbout));
    }
    
    [HttpPost]
    public ActionResult Index(IndexViewModel viewModel)
    {
      viewModel.SaveChanges()/DoWork()/Whatever();
      return View(new viewModel());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get basic skills in working with bits using C#.NET. I posted
Now, I'm a real beginner, just starting, figuring out things, testing and trying html
I am a real beginner learning to use Python using Zed Shaw's Learn Python
I am a real beginner in web development. The following code is failing at
I am a beginner and I cannot understand the real effect of the Iterable
Real problem with an existing webapp which has been working for the last couple
I am a real beginner at this so sorry if I am makin awfull
This is a real beginner Hibernate problem. I have a problem with the mappings
I'm a beginner in practical real-world java programming. I don't really understand these basic
am sorry for this dumb beginner question, but i have a real problem understanding

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.