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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:31:49+00:00 2026-06-06T05:31:49+00:00

I have a ViewModel I am binding to a view: ProductViewModel model = Mapper.Map<Product,

  • 0

I have a ViewModel I am binding to a view:

ProductViewModel model = Mapper.Map<Product, ProductViewModel>(product);
return View(model);

The view (and viewmodel) is used to edit a Product so ProductViewModel has an ID property that corresponds to the ID in the database.

And to Post the ID back to the Controller I am doing this in my form on the view:

@Html.HiddenFor(x => x.Id)

Even though this works – I was wondering whether there was a better way to Post the ID back to the Controller? Route Values maybe? or is this a fairly standard pattern/approach?

  • 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-06T05:31:51+00:00Added an answer on June 6, 2026 at 5:31 am

    If I have a GET action that includes the id in my route: /Products/Edit/1 then I usually keep it as a route value:

    [HttpPost]
    public ActionResult Edit(int id, EditProductViewModel model)
    

    This is purely a preference of mine, though. There is no right or wrong way to do it.

    The nice thing about this method is you no longer need to pass it in using a Hidden value since it is part of the URL. Actually, if you do pass it in with a Hidden value I believe it will be ignored.

    Alternatively, since id is part of the route, you don’t even need to have a separate parameter:

    [HttpPost]
    public ActionResult Edit(EditProductViewModel model)
    
    public class EditProductViewModel 
    {
        public int Id { get; set; }
    }
    

    Again, this is purely a preference thing.

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

Sidebar

Related Questions

I have senario in which one view and view has binding with multiple ViewModel.
I have a textbox that i am binding to the viewmodel's string property. The
I have a ComboBox that has the SelectedItem bound to the ViewModel. <ComboBox SelectedItem={Binding
I have ViewModel, Which has a ObservableCollection[Employee] EmpCol , now that ViewModel is bind
I have a viewmodel that has an EF object as one of its properties.
I have a view model sent to the edit action of my controller. The
I have a ViewModel class that contains a list of points, and I am
I have a ViewModel which exposes the string property PageToolBarVisible which can be true
I have a ViewModel (AbstractContextMenu) that represents my context menu (IContextMenu), and I bind
ViewModel I have a property of type Member called KeyMember . The 'Member' type

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.