简体   繁体   中英

Pre-populate model value on MVC3 page

I am new to ASP MVC3 and I am trying to make a set of pages for creating and editing sales notes records for customers in our database. On the Customer detail page, I have a table that will display all sales notes for the selected customer and it has a "Create Note" button that goes to a create page for sales notes. How do I pass and pre-populate the CustomerID field on the note with the ID of the customer from the previous page? I searched for an example or tutorial that had this scenario but didn't find one. If you know of a public example a link to it or a direct answer to the question would be greatly appreciated.

You can accomplish this fairly easily with routing parameters. First you need to define the route for the create note action that takes a customer Id. Next, you need to create the action so that it accepts the parameter.

A quick Google search or "ASP.NET MVC Routing Parameters" turned up this URL which explains it very well: http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM