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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:41:46+00:00 2026-05-17T18:41:46+00:00

I am trying to work out whether I am misunderstanding something about ASP.NET MVC

  • 0

I am trying to work out whether I am misunderstanding something about ASP.NET MVC or whether I have found some sort of bug in ASP.NET MVC Beta 3. I am having a problem with a PartialView picking up the wrong model when using HTML Helper extensions

My controller code looks like this:

public ActionResult EditGeneral(MapGeneralViewModel vm)
{
    var query = MapGeneralViewModel.ToModel(vm, svcMaps);

    return PartialView("General", MapGeneralViewModel.FromModel(query));
}

In the case of this being an insert, the property vm.Id starts out as -1 and after the call to MapGeneralViewModel.ToModel it has been persisted the database and query.Id has a proper value.

The call to MapSettingsViewModel.FromModel returns a new viewmodel and I have checked that the Id property correct contains the newly created id value.

The relevant bits of the view look like:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<AdminWebRole.Models.Map.MapGeneralViewModel>" %>
            <%: Model.Id %>
            <%= Html.Hidden("IdTest", Model.Id) %>
            <%= Html.HiddenFor(model => model.Id) %>

If I put a breakpoint in the view, Model.Id is correctly set to the right value.

The actual output of the controller (when Model.Id == 70) looks like this:

    70
    <input id="IdTest" name="IdTest" type="hidden" value="-1" />
    <input id="Id" name="Id" type="hidden" value="-1" />

So the value output without using the HTML helpers is correct, but the values output by the helpers somehow is picking up the viewmodel that was passed into the controller !

I have no idea how this is happening. I have tried various things:

  • Using View() rather than PartialView()
  • assigning the results of MapGeneralViewModel.FromModel() to vm and then passing vm to the view
  • using <%: and <%=
  • setting vm to null (the old view model somehow still gets used)
  • changing the value of the incoming id to 0 (results in 0 being output in the view instead of -1)
  • the problem isn’t specific to properties called “Id”, I have also tested other fields with the same result

Am I confused over how this is supposed to work or have I hit a beta bug ? If it makes any difference, this is running inside my local Azure runtime on a Win7 64 bit machine.

  • 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-17T18:41:47+00:00Added an answer on May 17, 2026 at 6:41 pm

    There is no way that MVC is just picking up a variable that you haven’t explicitly passed to your view or have hanging around in Session or TempData.

    Since you’re setting that Id to -1 I’m start there for problems.

    The other possibility is that -1 is hanging around in your ModelState someplace. The HTML helpers look to ModelState first before deciding to use any values you pass in.

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

Sidebar

Related Questions

I found this in an error log and am trying to work out how
I've been reading about the @font-face rule and trying to work out if it's
I'm trying to work this out. In my project, i have a file called
I have been trying to use a formula that is used to work out
I'm trying to work out whether we should try out Condor or Sun Grid
I've been trying to work out whether it's possible to manage (i.e. add tables,
I'm trying to work out how to go about checking a text area to
I'm trying to work out how to organize an android application that will have
I'm trying to work out how this can be achieved using jQuery, I have
I have a simple question for everyone. I am trying to work out how

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.