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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:26:50+00:00 2026-05-20T18:26:50+00:00

Scenario Route: /template/customize/10 Where: 10 = ID of Template() In the controller the model

  • 0

Scenario
Route: /template/customize/10
Where: 10 = ID of Template()

In the controller the model is created based on the template so that the View’s model is actually a Customization() object which actually has an Id of 0 because it’s new.

In the view I render @Html.HiddenFor( m => m.Id ) and the resulting value of that hidden input is 10, though it should be 0 because m is of type Customization. I’ve run into this before with MVC 2 and worked around it by not using helper methods.

Questions

  1. Is there annotation or something I
    can add to the Html Helper method to
    actually render the correct value?

  2. Is this a bug (MVC seems to be
    rendering m.Id as the route value
    regardless of what the actual model
    is set to in the controller)?

Additional code for clarification

View

@model Project.Core.Domain.Customization
@using( Html.BeginForm( "save", "customization" ) )
{
    @Html.HiddenFor( m => m.Id )
    @Html.HiddenFor( m => m.Template.Id )
    <button type="submit" id="save" name="save">Save</button>
}

Controller

       public ActionResult Customize( int id )
    {
        var template = Persistence.Data.RetrieveObject<Template>( id );
        var model = new Customization();

        ViewBag.Template = template;
        return ( View( model ) );
    }

Solution

Changed signature of Action to:

public ActionResult Customize( int TemplateId ){ ... }

Changed link to action as such:

@Html.ActionLink( "customize", "customize", new { TemplateId = template.Id } )

I end up with a url that looks like

/template/customize?TemplateId=10

It’s uglier, but I get to keep my view clean with model.Id so this is a win for me.

  • 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-20T18:26:51+00:00Added an answer on May 20, 2026 at 6:26 pm

    I think this is because when you use something like @Html.HiddenFor( m => m.Id ) the html helpers look in various places to populate the input’s value, and the values in the route is one of those places.

    So you could either change your route so that it’s something like template/customize/{TemplateId} and then have your action method reflect this, e.g. public ActionResult Customize(int templateId).

    OR you could change your viewmodel (or create a custom view model) that has a CustomizationId property rather than just Id.

    And no, it’s not a bug… it’s more of a feature that can have unforeseen consequences. But once you’re aware of it, it works like a treat.

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

Sidebar

Related Questions

Scenario I have a Sinatra App I have a route that fetches articles based
Scenario 1 This involves using one gateway route in app.yaml and then choosing the
The scenario is that I have a list of window handles to top level
Here is the scenario. DMZ box has the main application written ASP.NET running on
I've got a scenario where we have a customer who has a linux hosted
I have a question about global.asax that I don't really understand. My scenario is
For a scenario, I have a ASP.NET MVC application with URLs that look like
I have an asp.net mvc app with a route that allows users to request
i need to model the following scenario, but I can't get it working with
Suppose a scenario like below : Class User {} // User has Admin Role

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.