1

asp.net mvcの「編集/レビュー/保存」シナリオでのクリーンなアプローチを探しています:

お客様は月々の保険料に影響するアカウント情報を「編集」することができますが、必要な情報を保存する前に「レビュー」画面を提示して、変更内容を確認し、月々の保険料の詳細な内訳と同意するかどうかを確認できます。次に、「保存」を行います。

基本的には、次の 3 ステップの編集です。

ステップ 1 - 「編集」 - ユーザーが情報を編集する画面 ステップ 2 - 「レビュー」 - 入力したデータをレビューするための画面上の情報のみを読み取る ステップ 3 - 「保存」 - データの実際の保存。

興味深いのは、さまざまな小さな「編集」画面が多数あるのに、「レビュー」画面は 1 つしかないことです。

Edit/Post のセッションにデータを保存し、保存時にそれを取得することで可能ですが、良い方法とは思えません。

mvcでこれを行うよりクリーンな方法はありますか?

4

1 に答える 1

2

TempDataにデータを保存できますが、そのようにする必要はありません。

あなたは3つの行動を持つことができます:

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Edit() {
    //Returns the Edit view that displays an edit form
    //That edit form should post to the same action but with POST method.
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(AccountInformationModel m) {
    //Checks the form data and displays the errors in the 
    //edit view if the form data doesn't validate
    //If it does validate, then returns the Review view which renders 
    //all the form fields again but with their type as "hidden".
    //That form should post to Save action
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save(AccountInformationModel m) {
    //Checks the form data again (just to be safe in case 
    //the user tampers the data in the previous step)
    //and displays the errors in the edit view if it doesn't validate.
    //if it does validate, saves the changes.
}
于 2010-02-16T09:32:07.850 に答える