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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:08:06+00:00 2026-05-30T23:08:06+00:00

I have a strongly typed razor view for a model in my MVC 3

  • 0

I have a strongly typed razor view for a model in my MVC 3 project. Basically its for editing the model.

The model contains an Id field for the database key and some other string fields (Its a viewModel and all but thats not the point of the question).

In the view I just have a form and a submit button and nothing else. When the View is posted to the controller the model in the controller has all fields empty EXCEPT for the Id field which seems to have been auto-magically filled up.

How and where does the Id field gets populated in the model without there being a corresponding ‘input’ element for it in the view.

This is probably a dumb question but I would appreciate even just a link to what I should read up on. Thanks.

  • 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-30T23:08:07+00:00Added an answer on May 30, 2026 at 11:08 pm

    I bet it comes from the url as route parameter.

    For example you have the following controller:

    public class HomeController: Controller
    {
        public ActionResult Index(int id)
        {
            vqr model = GetModel(id);
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            // the model.Id property will be automatically populated here
            // because the request was POST /home/index/123
            ...
        }
    }
    

    and the following view:

    @model MyViewModel
    @using (Html.BeginForm())
    {
        <button type="submit">OK</button>
    }
    

    Now you navigate to GET /home/index/123 and you get the following markup:

    <form action="/home/index/123" method="post">
        <button type="submit">OK</button>
    </form>
    

    Notice the action attribute of the form? That’s where the id comes from. Basically the Html.BeginForm() helper uses the current url when generating the action attribute, and since the current url is /home/index/123 it is what gets used.

    And because if you have left the default routes in your Global.asax, the {id} route token is used at the end of the url, the default model binder successfully binds it to the Id property of your view model.

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

Sidebar

Related Questions

i have a strongly typed asp.net-mvc view and the Model has a . Links
I have a strongly-typed view that receives a Design model for its rendering. My
I have a strongly typed view of type ProductListingViewModel which in turn contains a
I have a model inside a strongly typed view but I would like there
I have a question about the use of the strongly typed model in Razor
I have a strongly-typed view with a @model declaration: @model MyViewModel When using extension
I have a strongly-typed MVC View Control which is responsible for the UI where
I have a strongly typed View that accepts a Customer model, this customer model
I have a strongly typed view, Edit, with a model named OrderModel. In this
I have a strongly typed MVC3 Razor view in which I want to display

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.