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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:19:38+00:00 2026-05-20T05:19:38+00:00

I have a very simple viewmodel class, and a strongly typed view (which uses

  • 0

I have a very simple viewmodel class, and a strongly typed view (which uses this class as a viewmodel).

public class MatchModelRequest
{
    public string Country { get; set; }
    public string Make { get; set; }
    public string Model { get; set; }
    public DateTime RegDate { get; set; }
    public int EnginePower { get; set; }
    public string FuelType { get; set; }
    public string BodyType { get; set; }
    public string Transmission { get; set; }
    public int Cc { get; set; }
    public int Doors { get; set; }
}

The problem is that there is a property named “Model” in there.

When I just do this in the view:

<%= Html.EditorFor(m => m) %>

I get a nice form with all the properties of MatchModelRequest. No problem at all (also not with the modelbinding, when retrieving the values back in a MatchModelRequest object).

But when I split them out in individual fields like this on the view:

<div class="editor-field">
    <%= Html.TextBoxFor(m => m.Model)%>
    <%= Html.ValidationMessageFor(m => m.Model)%>
</div>

I get an unhandled exception System.ArgumentException: Value cannot be null or empty, on the first line above where m.Model is used.

I suppose this has something to do with the Model property on ViewPage, but I don’t see what I can do to solve this problem other than just giving that property another name.

Giving that property another name is possible now in my case, but I would like to keep it named “Model”. And it’s not always possible to change the properties of your model.

Edit

I’ve been further investigating this, and apparently the part where this goes wrong is situated in System.Web.Mvc.ExpressionHelper in the GetExpressionText(LambdaExpression expression) method. There there are the following lines:

// If it starts with "model", then strip that away
if (nameParts.Count > 0 && String.Equals(nameParts.Peek(), ".model", StringComparison.OrdinalIgnoreCase)) {
    nameParts.Pop();
}

And this is where the actual “model” part is stripped of… so I guess this is by design then, and I don’t have another option then to rename my property?

Suggestions are still welcome.

Btw, this is MVC 2. Could somebody check if this code is still present in MVC 3?

  • 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-20T05:19:38+00:00Added an answer on May 20, 2026 at 5:19 am

    Yeah, that’s right. I’ve looked at the MVC 3 RTM source and there is two places where the “Model” is removed from the expression. First one is when we use the string expression like @Html.TextBoxFor("model").

        public static string GetExpressionText(string expression) {
            return
                String.Equals(expression, "model", StringComparison.OrdinalIgnoreCase)
                    ? String.Empty    // If it's exactly "model", then give them an empty string, to replicate the lambda behavior
                    : expression;
        }
    

    The other is on the GetExpressionText(LambdaExpression expression) as you said before.

        // If it starts with "model", then strip that away
        if (nameParts.Count > 0 && String.Equals(nameParts.Peek(), ".model", StringComparison.OrdinalIgnoreCase)) {
            nameParts.Pop();
        }
    

    So, I think the best solution by now is to rename your property 🙂

    UPDATE: Actually, it works on Mvc3, I just tested it. There is a fix in the code, see this:

    else if (part.NodeType == ExpressionType.Parameter) {
        // Dev10 Bug #907611
        // When the expression is parameter based (m => m.Something...), we'll push an empty
        // string onto the stack and stop evaluating. The extra empty string makes sure that
        // we don't accidentally cut off too much of m => m.Model.
        nameParts.Push(String.Empty);
        part = null;
    }
    else {
        break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple migration which was created using the generator class AddEmailToUsers
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple problem which requires a very quick and simple solution
I have a very simple WPF application in which I am using data binding
I have encountered something very strange, simple WPF application <Window x:Class=ListBoxSelection.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow
I have a very simple ruby rack app which retrieves information from a webservice
i have very simple problem. I need to create model, that represent element of
I have a very simple bit of script that changes the status of an
I have a very simple TCP server written in C. It runs indefinitely, waiting
I have a very simple Java RMI Server that looks like the following: import

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.