ASP.NET MVC Framework (Part 4): Handling Form Edit and Post Scenarios
page 12 of 15
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 59424/ 252

Implement Edit Product Functionality (Part 2 - Edit View)

We can implement the "Edit.aspx" view page using the following approach:

Figure 36

Note how we are using both the Html.TextBox and Html.Select helper methods in the sample above.  Both of these are extension methods from the MVCToolkit.dll assembly.

Notice how the Html.Select helper method has an overloaded version that allows you to specify what the selected value is in the dropdownlist.  In the snippet below I'm indicating that I want the Category drop down item to be automatically selected based on the edit product's current CategoryID value:

Figure 37

Lastly - notice how we are using the Url.Action() helper method to set the <form> element's "action" attribute:

Figure 38

Both the Url.Action and Html.ActionLink helper methods use the ASP.NET MVC Framework's Routing Engine to generate URLs (read Part 2 for details on how URL generation works).  What this means is that if we change the routing rules for Edits in our site, we will not need to change any of the code in our Controller or View.  For example, we could re-map our URLs to use a more RESTful URL like /Products/1/Edit instead of /Products/Edit/1, and have the above Controller and View continue to work unmodified. 


View Entire Article

User Comments

Title: Stuck / adding Creat & New to my Controller.cs   
Name: Casey
Date: 2009-07-29 4:08:45 PM
Comment:
Hi,
I'm a newbie as if you don't hear that all day long.

I have setup a project that is to allow me to post information to a SQL database, and view the updated information. I can view just fine, however I'm stuck on where in my code to add the Create, and New Methods. If you would like to look at my code I can post it or email it.

Thank you,

Casey,
Title: text search for an table in asp.net mvcframework   
Name: senthil
Date: 2009-02-07 8:42:22 AM
Comment:
i want to make an text search on a column in a table.
for exampe i type a name in the text box and click a button then it should search the name in the column .

hope u help me

thanks in advance






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2020 ASPAlliance.com  |  Page Processed at 2020-07-05 11:26:50 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search